두 개의 테이블이 있습니다. 표 reports
Laravel의 피벗 테이블에서 행 삭제
report_id | user_id | item_id
및 reports_messages
report_id | user_id | item_id | messages
내가 reports_messages
에 report_id
일치하는 모든 관련 행이 너무 삭제 될 reports
에 report_id
을 삭제하면 내가 원하는. 내 ReportMessages 모델에서
나는
public function reportedItem(){
return $this->belongsTo('App\Item');
}
public function user(){
return $this->hasOne('App\User', 'id', 'user_id');
}
지금까지 내가 SO
public function destroy($report_id){
Report::destroy($report_id);
ReportMessages::find(1)->reports()->where('report_id',$report_id)->delete();
return redirect()->route('user.ports');
이 삭제 여기에 설립 된이 솔루션을 시도한 보고서 모델에서이 관계
public function reports(){
return $this->belongsTo('App\Report');
}
public function item(){
return $this->belongsTo('App\Item', 'item_id', 'id');
}
에게 있습니다 reports
에서만 ... 피봇 테이블에서 관련 report_id를 삭제하지 않습니다. }
감사합니다. 이 오류가 발생했습니다. '정의되지 않은 메소드 호출 \ Database \ Query \ Builder :: detach()'가 나타납니다. – user5996816
내 대답이 업데이트되었지만 실제로 피벗 테이블이 없습니다 ... – Jerodev
오, 맙소사. 그리고 저는 피봇 테이블을 가지고 그것을하려고했습니다. 그들은 실제로 모델에 의해서만 연결됩니다. 바보 나. 도와 주셔서 감사합니다! – user5996816