1
我有這個DB模式如何從多形態的關係許多刪除的對象很多laravel 4
行程:是,名
服務:ID,名稱
圖片:身份證,名稱
可描述:picture_id,picturable_id,picturable_type。
旅遊和服務可以有圖片,所以我在宣佈這款車型多形態關係
Travel.php
public function pictures()
{
return $this->morphToMany('Picture', 'picturable');
}
Service.php
public function pictures()
{
return $this->morphToMany('Picture', 'picturable');
}
Picture.php
public function travels()
{
return $this->morphedByMany('Travel', 'picturable');
}
public function services()
{
return $this->morphedByMany('Service', 'picturable');
}
我創建
$this->service->pictures()->save(Picture::find(Input::get('new_picture')));
的relarion但是當我試圖刪除,我不工作
$service->pictures()->detach();
我覺得detach()會刪除關聯,delete()會刪除物理上的記錄。 – Qazi