PHPackages                             razisayyed/laravel-cascaded-soft-deletes - 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. razisayyed/laravel-cascaded-soft-deletes

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

razisayyed/laravel-cascaded-soft-deletes
========================================

Cascades delete/restore Soft Deletable relationships

v1.0.4(2y ago)94.1k1[1 PRs](https://github.com/razisayyed/laravel-cascaded-soft-deletes/pulls)MITPHPPHP ^7.3|^8.1

Since Jan 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/razisayyed/laravel-cascaded-soft-deletes)[ Packagist](https://packagist.org/packages/razisayyed/laravel-cascaded-soft-deletes)[ RSS](/packages/razisayyed-laravel-cascaded-soft-deletes/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (5)Versions (8)Used By (0)

[![Tests](https://github.com/razisayyed/laravel-cascaded-soft-deletes/actions/workflows/php.yml/badge.svg)](https://github.com/razisayyed/laravel-cascaded-soft-deletes/actions/workflows/php.yml)[![codecov](https://camo.githubusercontent.com/fc0166cafc420a7a0cd4f7ac6b5b8a8b632e665898e30aad34474a7e431d87c3/68747470733a2f2f636f6465636f762e696f2f67682f72617a697361797965642f6c61726176656c2d63617363616465642d736f66742d64656c657465732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d3845343851463234354d)](https://codecov.io/gh/razisayyed/laravel-cascaded-soft-deletes)[![Total Downloads](https://camo.githubusercontent.com/185e56c1930e785857947ecfc3e45253b2c5d25879fffdb5050f80f7f5c36bb2/68747470733a2f2f706f7365722e707567782e6f72672f72617a697361797965642f6c61726176656c2d63617363616465642d736f66742d64656c657465732f646f776e6c6f6164732e737667)](https://packagist.org/packages/razisayyed/laravel-cascaded-soft-deletes)[![Latest Stable Version](https://camo.githubusercontent.com/902473a90a750b56a533951ac98acfa8c8055fe8212d8309f9c436d5406f4323/68747470733a2f2f706f7365722e707567782e6f72672f72617a697361797965642f6c61726176656c2d63617363616465642d736f66742d64656c657465732f762f737461626c652e737667)](https://packagist.org/packages/razisayyed/laravel-cascaded-soft-deletes)[![Latest Unstable Version](https://camo.githubusercontent.com/5785ebc652de3dbdc32a8d2c5ae91c9d246ab2a5036415fbddf2088fa93167c7/68747470733a2f2f706f7365722e707567782e6f72672f72617a697361797965642f6c61726176656c2d63617363616465642d736f66742d64656c657465732f762f756e737461626c652e737667)](https://packagist.org/packages/razisayyed/laravel-cascaded-soft-deletes)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/13d4ae2b33d3ad62e4162501023ffc0c2b30d508c33db1aaff29244e95b86f75/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617a697361797965642f6c61726176656c2d63617363616465642d736f66742d64656c657465732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/razisayyed/laravel-cascaded-soft-deletes/?branch=main)[![License](https://camo.githubusercontent.com/c8212c30da4c56bd2d0850c1cc6653404203bd54a235c1ee6cb58733bf3bff2f/68747470733a2f2f706f7365722e707567782e6f72672f72617a697361797965642f6c61726176656c2d63617363616465642d736f66742d64656c657465732f6c6963656e73652e737667)](https://packagist.org/packages/razisayyed/laravel-cascaded-soft-deletes)

This is a Laravel 8 package for cascding SoftDeletes delete/restore actions.

- **Laravel 7.0** is supported from v0.1.0 to v1.0.2
- **Laravel 8.0** is supported from v0.1.0 to v1.0.2
- **Laravel 9.0** is supported since v1.0.2
- **Laravel 10.0** is supported since v1.0.4 (Thanks to [@mojowill](https://github.com/mojowill))

Although this project is completely free for use, I appreciate any support!

- **[Donate via PayPal](https://www.paypal.me/RaziAlsayyed)**

**Contents:**

- [Features](#features)
- [Notes](#notes)
- [Installation](#installation)
- [License](#license)

Features
--------

[](#features)

- Cascade soft delete for chosen relations
- Cascade restore for chosen relations (only models with deleted\_at &gt;= restoredInstance-&gt;deleted\_at value will be restored)
- Ability to follow [custom query](#custom-queries)
- By default all cascade action will be added to default queue, you can change this behaviour by [publishing package's config file](#publish-config).

Notes
-----

[](#notes)

- The idea of this package has been extracted from the fabulous package [laravel-nestedset](https://github.com/lazychaser/laravel-nestedset)
- Because the package relies on deleted\_at column to make the comparision when it cascades restore action, it is recommended to use `$table->softDeletes('deleted_at', 6);` in the migration files. Otherwise, you may restore a related model that has been deleted before the instance in a fraction of a second.

Installation
------------

[](#installation)

To install the package, in terminal:

```
composer require razisayyed/laravel-cascaded-soft-deletes

```

### publish config

[](#publish-config)

If you need to change config values for sync/async behaviour you may issue:

```
php artisan vendor:publish --provider="RaziAlsayyed\LaravelCascadedSoftDeletes\Providers\CascadedSoftDeletesProvider" --tag="config"

```

### Setting up

[](#setting-up)

to setup CascadedSoftDeletes you need to use the trait at the parent model and define `$cascadedSoftDeletes` property or `getCascadedSoftDeletes()` method.

### Simple example with $cascadedSoftDeletes property

[](#simple-example-with-cascadedsoftdeletes-property)

```
...
