PHPackages                             litvinjuan/laravel-cascade-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. litvinjuan/laravel-cascade-soft-deletes

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

litvinjuan/laravel-cascade-soft-deletes
=======================================

Cascades soft delete and restored operations to the defined relationships

0.2(1y ago)02.8k↓44.4%[3 PRs](https://github.com/litvinjuan/laravel-cascade-soft-deletes/pulls)MITPHPPHP ^8.2CI passing

Since Sep 26Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/litvinjuan/laravel-cascade-soft-deletes)[ Packagist](https://packagist.org/packages/litvinjuan/laravel-cascade-soft-deletes)[ Docs](https://github.com/litvinjuan/laravel-cascade-soft-deletes)[ GitHub Sponsors](https://github.com/litvinjuan)[ RSS](/packages/litvinjuan-laravel-cascade-soft-deletes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (12)Versions (6)Used By (0)

Cascades soft delete and restore operations in Laravel Models
=============================================================

[](#cascades-soft-delete-and-restore-operations-in-laravel-models)

[![Latest Version on Packagist](https://camo.githubusercontent.com/60332b779ac1f68aa12ea51734bf2678159c0fb3ee63ae1225bc1d331c76be4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c697476696e6a75616e2f6c61726176656c2d636173636164652d736f66742d64656c657465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/litvinjuan/laravel-cascade-soft-deletes)[![GitHub Tests Action Status](https://camo.githubusercontent.com/5d29a6bbea95da763f7835147c3001b03cd76676953fa46722e0ed18cc15a080/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c697476696e6a75616e2f6c61726176656c2d636173636164652d736f66742d64656c657465732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/litvinjuan/laravel-cascade-soft-deletes/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/5080b963e7cc1290b96a8a1814159cb8c310d4bf98b651e6c902c97b67354cfd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c697476696e6a75616e2f6c61726176656c2d636173636164652d736f66742d64656c657465732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/litvinjuan/laravel-cascade-soft-deletes/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/4e412e738afe7e6db23f618b7b95a31633d4ae33158567dfa7bbf60334c82e02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c697476696e6a75616e2f6c61726176656c2d636173636164652d736f66742d64656c657465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/litvinjuan/laravel-cascade-soft-deletes)

This package is for cascading soft delete and restore operations on your related models. When a model gets soft deleted, the configured related models get soft deleted as well. When the original model is restored, its soft-deleted related models algo get restored.

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

[](#installation)

You can install the package via composer:

```
composer require litvinjuan/laravel-cascade-soft-deletes
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-cascade-soft-deletes-config"
```

Soft Deleting
-------------

[](#soft-deleting)

Simply add the trait to your models and configure the cascading relations either via the `cascadeSofDeleteRelations` property or the `getRelationsForCascadeSoftDeletes` method.

If your cascading related model also has the `CascadeSoftDeletes` trait, its related models will also be soft-deleted.

In the following example, soft deleting a project, will also soft delete its tasks. And soft deleting a team, will soft delete its projects, and in turn, all their respective tasks will also be soft deleted.

```
class Team extends Model
{
    use CascadeSoftDeletes;

    protected $cascadeSofDeleteRelations = ['projects'];

    public function projects() {
        return $this->hasMany(Project::class);
    }
}

class Project extends Model
{
    use CascadeSoftDeletes;

    protected $cascadeSofDeleteRelations = ['tasks'];

    public function team() {
        return $this->belongsTo(Team::class);
    }

    public function task() {
        return $this->hasMany(Task::class);
    }
}

class Task extends Model
{
    public function project() {
        return $this->belongsTo(Project::class);
    }
}
```

Restoring
---------

[](#restoring)

Restoration works very similarly. By default, it restores the same relations that were soft deleted, but you can customize the relations to be restored by setting the `cascadeRestoreRelations` or implementing the `getRelationsForCascadeRestore`.

If you want to disable restoration all together, go into the `cascade-soft-deletes` config and set `cascade_restores` to `false`.

By default, when restoring related models, the package will only restore models that were deleted at the same time or after the parent model. This is to make sure we don't restore a child model that was soft deleted individually in a previous time. If you want to restore all models regardless of when they were soft deleted, you can go into the configuration file and set `ignore_deleted_at_when_restoring` to `true`.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Juan Litvin](https://github.com/litvinjuan)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance70

Regular maintenance activity

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~209 days

Total

2

Last Release

390d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/caac9d056df003d8d88cb3e8540834ecfc31c90e08c4ccd67a38e869742e45ee?d=identicon)[litvinjuan](/maintainers/litvinjuan)

---

Top Contributors

[![litvinjuan](https://avatars.githubusercontent.com/u/42967171?v=4)](https://github.com/litvinjuan "litvinjuan (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")

---

Tags

laravellitvinjuanlaravel-cascade-soft-deletes

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/litvinjuan-laravel-cascade-soft-deletes/health.svg)

```
[![Health](https://phpackages.com/badges/litvinjuan-laravel-cascade-soft-deletes/health.svg)](https://phpackages.com/packages/litvinjuan-laravel-cascade-soft-deletes)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
