Answer the question
In order to leave comments, you need to log in
Laravel event when deleting by foreign key?
Let's say there are Category and Product models. They are connected one to many.
The provider has event Product::deleted().
But it only works if you delete the product.
How to call it if the product is automatically deleted when the category is deleted?
Answer the question
In order to leave comments, you need to log in
class Category extends Eloquent
{
public function products()
{
return $this->has_many('Product');
}
protected static function boot() {
parent::boot();
static::deleting(function($Category) {
$Category->products()->delete();
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question