DEV Community

Discussion on: Laravel: Softdelete Eloquent Relationships onDelete Cascade

Collapse
 
mah3uz profile image
Mahfuz Shaikh

Thank you. Great approch.
One thing I can confirm with Laravel 8 that restore would not work,
It should be like:

static::restoring(function($resource) {
    foreach (static::$cascade_relations as $relation) {
        foreach ($resource->{$relation}()->withTrashed()->get() as $item) {
            $item->restore();
        }
    }
});
Enter fullscreen mode Exit fullscreen mode
Collapse
 
waiylkarim profile image
WAIYL KARIM • Edited

With Laravel 8, it would be better to use Observers instead