PHPackages                             touhidurabir/laravel-model-soft-cascade - 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. touhidurabir/laravel-model-soft-cascade

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

touhidurabir/laravel-model-soft-cascade
=======================================

A laravel package to handle cascade delete and restore on model relations.

1.0.1(4y ago)18402[1 PRs](https://github.com/touhidurabir/laravel-model-soft-cascade/pulls)MITPHPPHP &gt;=7.4

Since Oct 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/touhidurabir/laravel-model-soft-cascade)[ Packagist](https://packagist.org/packages/touhidurabir/laravel-model-soft-cascade)[ RSS](/packages/touhidurabir-laravel-model-soft-cascade/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Laravel Model Soft Cascade
==========================

[](#laravel-model-soft-cascade)

A laravel package to handle cascade delete and restore on model relations.

This package not only handle the cascade delete of chile models on parement model soft delete but also the cascade restore of child model records on parent model restore form soft deleted state . At the same time it can handle the cascade force delete that is by force deleting the parent , all the child will also force delete . See the config file to get more details .

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

[](#installation)

Require the package using composer:

```
composer require touhidurabir/laravel-model-soft-cascade
```

To publish the config file:

```
php artisan vendor:publish --provider="Touhidurabir\ModelSoftCascade\ModelSoftCascadeServiceProvider" --tag=config
```

Configurations
--------------

[](#configurations)

The config file **soft-cascade** file contains most of the basic configurations details like for which delete or restore event, it will invoke the cascading functionality, should the cascading run as database transactional operation, how it will behave when models get force deleted etc . For full details check the config file .

> Note that eveen though these configurations are set as global for all models, it is possible to oberride them for model specific way . Check the Usage section to know how to have specific configurations for specific model while maintaining the global configurations.

Usage
-----

[](#usage)

To use this, simply use the trait **HasSoftCascade** in model and implement the abstract method **cascadable** which will return an **array** .

```
class User extends Model {

    use SoftDeletes;

    use HasSoftCascade;

    public function cascadable() : array {

        return [
            'profile', 'posts'
        ];
    }

    public function profile() {

        return $this->hasOne('Touhidurabir\ModelSoftCascade\Tests\App\Profile');
    }

    public function posts() {

        return $this->hasMany('Touhidurabir\ModelSoftCascade\Tests\App\Post');
    }
}
```

> Note : Make sure that model do use the **SoftDeletes** trait otherwise it will throw exception .

By default the **cascadable** should return an array which contains the relations methods name for which we want to apply cascadable behaviour . The rest of the configurations will be pull from the published config file . But it is possible to override this on model specific way . Such as :

```
/**
 * The cascade custom configurations
 *
 * @return array
 */
public function cascadable() : array  {

    return [
        'delete' => [
            'enable'    => true,
            'event'     => 'deleted',
            'relations' => [...],
            'force'     => true,
        ],
        'restore' => [
            'enable'    => true,
            'event'     => 'restored',
            'relations' => ['comments'],
        ]
    ];
}
```

The above example display all the possible options to set for specific model to determine how the cascade functionality should work for that specific model .

One notebale case of the above example is that by following this model specific configuration, it is possible to only use the **delete** or **restore** cascade behaviour for a given model . This is done by not setting the **delete** or **restore** key of the return array of **cascadable** . For example, only to have delete cascade behavioud, do as following :

```
/**
 * The cascade custom configurations
 *
 * @return array
 */
public function cascadable() : array  {

    return [
        'delete' => [
            'enable'    => true,
            'event'     => 'deleted',
            'relations' => [...],
            'force'     => true,
        ]
    ];
}
```

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

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License
-------

[](#license)

[MIT](./LICENSE.md)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~0 days

Total

2

Last Release

1723d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c6009d764c48df4a55a8645c349f90a99c7e6e694b06c60b580e1da278d1db5?d=identicon)[touhidurabir](/maintainers/touhidurabir)

---

Top Contributors

[![touhidurabir](https://avatars.githubusercontent.com/u/2587979?v=4)](https://github.com/touhidurabir "touhidurabir (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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