Laravel 5.4 - Deleting specific records from the pivot table Laravel 5.4 - Deleting specific records from the pivot table laravel laravel

Laravel 5.4 - Deleting specific records from the pivot table


You can use wherePivot() method to detach specific product from the visit.

$visits = Visit::find($visit_id);$visits->products()->wherePivot('product_id','=',$product_id)->detach();

UpdateAs given in Laravel docs "Attaching / Detaching" section, you can pass the related model's id that you want to remove in detach() method. Example

$visits = Visit::find($id);$visits->products()->detach($product_id);