PHPackages                             pellesam/laravel-cascade-soft-delete-and-restore - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pellesam/laravel-cascade-soft-delete-and-restore

ActiveUtility[Database &amp; ORM](/categories/database)

pellesam/laravel-cascade-soft-delete-and-restore
================================================

Cascading delete and restore for Eloquent models that implement soft delete

4.2.0(4y ago)021MITPHPPHP ^7.3|^8.0

Since May 3Pushed 4y agoCompare

[ Source](https://github.com/SamuelPelletier/laravel-cascade-soft-deletes)[ Packagist](https://packagist.org/packages/pellesam/laravel-cascade-soft-delete-and-restore)[ RSS](/packages/pellesam-laravel-cascade-soft-delete-and-restore/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (21)Used By (0)

Cascading soft delete and restore for the Laravel PHP Framework
===============================================================

[](#cascading-soft-delete-and-restore-for-the-laravel-php-framework)

Introduction
------------

[](#introduction)

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 `ON DELETE CASCADE` 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](https://laravel.com/docs/5.2/eloquent#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 `SoftDeletes` trait.

Code Samples
------------

[](#code-samples)

```
