Laravel Eloquent ORM - Many to Many Delete Pivot Table Values left over

前端 未结 4 1696
抹茶落季
抹茶落季 2020-12-28 13:06

Using Laravel, I have the following code

$review = Review::find(1);
$review->delete();

Review has a many to many relationsh

4条回答
  •  庸人自扰
    2020-12-28 14:06

    i guess you have a error in your models relationship conception, the product has many reviews but the review associated with one product so you have here one to many relationship. but in general the answer in the general case will be using:

    $product->reviews()->sync([]);
    

提交回复
热议问题