Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.