Need help with laravel-cascade-soft-deletes?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

659 Stars 57 Forks MIT License 107 Commits 0 Opened issues


Cascading deletes for Eloquent models that implement soft deletes

Services available


Need anything else?

Contributors list

Cascading soft deletes for the Laravel PHP Framework

Build Status Latest Stable Version Total Downloads License Buy us a tree


In scenarios when you delete a parent record - say for example a blog post - you may want to also delete any comments associated with it as a form of self-maintenance of your data.

Normally, you would use your database's foreign key constraints, adding an

rule to the foreign key constraint in your comments table.

It may be useful to be able to restore a parent record after it was deleted. In those instances, you may reach for Laravel's soft deleting functionality.

In doing so, however, you lose the ability to use the cascading delete functionality that your database would otherwise provide. That is where this package aims to bridge the gap in functionality when using the


Code Samples

use App\Comment;
use Dyrynda\Database\Support\CascadeSoftDeletes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model { use SoftDeletes, CascadeSoftDeletes;

protected $cascadeDeletes = ['comments'];

protected $dates = ['deleted_at'];

public function comments()
    return $this->hasMany(Comment::class);


Now you can delete an

record, and any associated
records will be deleted. If the
record implements the
trait as well, it's children will also be deleted and so on.
$post = App\Post::find($postId)
$post->delete(); // Soft delete the post, which will also trigger the delete() method on any comments and their children.

Note: It's important to know that when you cascade your soft deleted child records, there is no way to know which were deleted by the cascading operation, and which were deleted prior to that. This means that when you restore the blog post, the associated comments will not be.

Because this trait hooks into the

Eloquent model event, we can prevent the parent record from being deleted as well as any child records, if any exception is triggered. A
will be triggered if the model does not use the
trait, or if any of the defined
relationships do not exist, or do not return an instance of

Additional Note: If you already have existing event listeners in place for a model that is going to cascade soft deletes, you can adjust the priority or firing order of events to have CascadeSoftDeletes fire after your event. To do this you can set the priority of your deleting event listener to be 1.

MODEL::observe( MODELObserver::class, 1 );
The second param is the priority.

MODEL::deleting( MODELObserver::class, 1 );

As of right now this is not documented in the Larvel docs, but just know that the default priority is

for all listeners, and that
is the lowest priority. Passing a param of greater than
to your listener will cause your listener to fire before listeners with default priority of


This trait is installed via Composer. To install, simply add to your

$ composer require dyrynda/laravel-cascade-soft-deletes


If you are having general issues with this package, feel free to contact me on Twitter.

If you believe you have found an issue, please report it using the GitHub issue tracker, or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts. Thanks!


You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees here

Read more about Treeware at

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.