PHPackages                             iatstut/laravel-cascade-soft-delete - 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. iatstut/laravel-cascade-soft-delete

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

iatstut/laravel-cascade-soft-delete
===================================

Cascading deletes for Eloquent models that implement soft deletes

06PHP

Since May 12Pushed 8y agoCompare

[ Source](https://github.com/michaedyrynda/laravel-cascade-soft-delete)[ Packagist](https://packagist.org/packages/iatstut/laravel-cascade-soft-delete)[ RSS](/packages/iatstut-laravel-cascade-soft-delete/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Cascading soft deletes for the Laravel PHP Framework
====================================================

[](#cascading-soft-deletes-for-the-laravel-php-framework)

v1.4.0
------

[](#v140)

[![Travis Build Status](https://camo.githubusercontent.com/3edccc06766294228ab13b24fe2d4de84fe8a5cfd31549fd1f6ce3338f74ebd1/68747470733a2f2f7472617669732d63692e6f72672f6d69636861656c647972796e64612f6c61726176656c2d636173636164652d736f66742d64656c657465732e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/3edccc06766294228ab13b24fe2d4de84fe8a5cfd31549fd1f6ce3338f74ebd1/68747470733a2f2f7472617669732d63692e6f72672f6d69636861656c647972796e64612f6c61726176656c2d636173636164652d736f66742d64656c657465732e7376673f6272616e63683d6d6173746572)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/852fbc7094d3d662c7a5d1bf527cb4e996647e566aea6cbd5736fdc4214e8db7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d69636861656c647972796e64612f6c61726176656c2d636173636164652d736f66742d64656c657465732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-cascade-soft-deletes/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/904c4d13e672beee3d6f9feaed7a7cb832061e509a7d294368ffc32df0a53441/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d69636861656c647972796e64612f6c61726176656c2d636173636164652d736f66742d64656c657465732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-cascade-soft-deletes/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/2c9d492081c6e5239a50485c50c52f60de5a39158007a5db0c3d86706170d0e6/68747470733a2f2f706f7365722e707567782e6f72672f69617473747574692f6c61726176656c2d636173636164652d736f66742d64656c657465732f762f737461626c65)](https://packagist.org/packages/iatstuti/laravel-cascade-soft-deletes)[![Total Downloads](https://camo.githubusercontent.com/05d85cf8cb4bc5e0ca60ebd38110e13c1679301cb79ae7d9a39f49a80bc83bb9/68747470733a2f2f706f7365722e707567782e6f72672f69617473747574692f6c61726176656c2d636173636164652d736f66742d64656c657465732f646f776e6c6f616473)](https://packagist.org/packages/iatstuti/laravel-cascade-soft-deletes)[![License](https://camo.githubusercontent.com/40cef79635e6fd5487a7a07b60cf9f6835be3e82d33449bcdd0a127b9f888b74/68747470733a2f2f706f7365722e707567782e6f72672f69617473747574692f6c61726176656c2d636173636164652d736f66742d64656c657465732f6c6963656e7365)](https://packagist.org/packages/iatstuti/laravel-cascade-soft-deletes)

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.

As of `v1.0.2`, you can inherit `CascadeSoftDeletes` from a base model class, you no longer need to use the trait on each child if all of your models happen to implement `SoftDeletes`.

As of `v1.0.4`, the package supports cascading deletes of grandchildren records ([\#8](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/issues/8), [\#9](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/pull/9)).

As of `v1.0.5`, the package has better support of `hasOne` relationships ([\#10](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/issues/10), [\#11](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/issues/11)).

`v1.1.0` adds compatibility with Laravel 5.3.

`v1.2.0` adds compatibility with Laravel 5.4.

`v1.3.0` adds compatibility with Laravel 5.5.

`v1.4.0` adds compatibility with Laravel 5.6.

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

[](#code-samples)

```
