phplaraveleloquentsoft-delete

How to cascade soft deletes in Laravel?


How can I (eloquently) cascade a soft delete in Laravel? So when there is a post with comments for example, where both tables have soft deletes. When I remove the post, I want to remove the comments at well.

I would expect something like:

class Post extends Model
{
    use SoftDeletes;

    protected $cascadeSoftDeletes = ['comments'];

    ...
}

Solution

  • you can do Apollo's solution or you could use a package that handle's this like

    https://github.com/michaeldyrynda/laravel-cascade-soft-deletes