I know this is from two weeks ago, but just in case I think what you're looking for is:
protected static function boot() {
parent::boot();
static::deleting(function($tutorial) { // called BEFORE delete()
$tutorial->blocks()->delete();
});
}
If you have children that might need to have their own cascading functions then you might need:
protected static function boot() {
parent::boot();
static::deleting(function($tutorial) { // called BEFORE delete()
foreach($tutorial->blocks as $block)
{
$block->delete(); // Causes any child "deleted" events to be called
}
});
}
There was a bug/quirk where statements like $tutorial->blocks()->delete(); were not calling the events on each child. I'm not sure if it's been fixed yet, so something like this is safer.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community