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

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

byteasc/laravel-soft-cascade
============================

Laravel Cascade Soft Delete &amp; Restore

10.0.0(3y ago)041.2k[1 PRs](https://github.com/iclassproinc/laravel-soft-cascade/pulls)MITPHPPHP ^8.0

Since May 2Pushed 1y agoCompare

[ Source](https://github.com/iclassproinc/laravel-soft-cascade)[ Packagist](https://packagist.org/packages/byteasc/laravel-soft-cascade)[ RSS](/packages/byteasc-laravel-soft-cascade/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (7)Versions (53)Used By (0)

[![Header](https://camo.githubusercontent.com/9532f1aa37a1b105e9c9fe9e3e5407c5b18a1f0a9a280a9ca22762eee98fcba4/68747470733a2f2f692e696d6775722e636f6d2f664b68626c6a542e706e67)](https://camo.githubusercontent.com/9532f1aa37a1b105e9c9fe9e3e5407c5b18a1f0a9a280a9ca22762eee98fcba4/68747470733a2f2f692e696d6775722e636f6d2f664b68626c6a542e706e67)

[![Build Status](https://camo.githubusercontent.com/dbbd8de07e4aebfcbf8c45b29851e33c0b5ca9424a2087cc6d6633c15979d070/68747470733a2f2f7472617669732d63692e6f72672f41736b6564696f2f6c61726176656c2d736f66742d636173636164652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Askedio/laravel-soft-cascade)[![Codacy Badge](https://camo.githubusercontent.com/22737c23256b973cf152cbd37c0f1c3a22852a6d405096d67eeea08217451cf8/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3538383737623838616233383435373639353231373835313635386134343362)](https://www.codacy.com/app/gcphost/laravel-soft-cascade?utm_source=github.com&utm_medium=referral&utm_content=Askedio/laravel-soft-cascade&utm_campaign=Badge_Grade)[![Codacy Badge](https://camo.githubusercontent.com/ebebab2e02f16e520a10657d0eb3b198c7971058dbaa89273c1a713bdae25bfb/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f436f7665726167652f3538383737623838616233383435373639353231373835313635386134343362)](https://www.codacy.com/app/gcphost/laravel-soft-cascade?utm_source=github.com&utm_medium=referral&utm_content=Askedio/laravel-soft-cascade&utm_campaign=Badge_Coverage)[![StyleCI Badge](https://camo.githubusercontent.com/c5756aee014b4ca4a7f7a3fa4aa90387ee3e7c83d55f4097b88738b979662e94/68747470733a2f2f7374796c6563692e696f2f7265706f732f35373339343731302f736869656c64)](https://styleci.io/repos/57394710)

Laravel/Lumen Soft Cascade Delete &amp; Restore
===============================================

[](#laravellumen-soft-cascade-delete--restore)

Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.

**Laravel****laravel-soft-cascade****Lifecycle**^5.5^5.5January 24, 2017Bug fixes until January 2019Security fixes until June 2020^5.6^5.6February 7, 20186 months of bug fixes1 year of security^5.7^5.7September 4, 20186 months of bug fixes1 year of security^5.8^5.8February 26, 20196 months of bug fixes1 year of security^6.0^6.0September 3, 2019Bug fixes until September 3, 2021Security fixes until September, 3 2022^7.0^7.0March 3, 2020Bug fixes until September 3, 2020Security fixes until March, 3 2021Why do I need it?
=================

[](#why-do-i-need-it)

### To make soft deleting and restoring relations easy.

[](#to-make-soft-deleting-and-restoring-relations-easy)

If you enjoy features like MySQL cascade deleting but want to use Laravels SoftDeletes feature you'll need to do some extra steps to ensure your relations are properly deleted or restored.

This package is intended to replace those steps with a simple array that defines the relations you want to cascade.

Installation
============

[](#installation)

Install with composer

```
composer require askedio/laravel-soft-cascade

```

From Laravel 5.5 onwards, it's possible to take advantage of auto-discovery of the service provider. For Laravel versions before 5.5, you must register the service provider in your config/app.php

```
Askedio\SoftCascade\Providers\GenericServiceProvider::class,

```

Lumen does not support the auto-discovery feature, you should manually add the provider.

```
Askedio\SoftCascade\Providers\LumenServiceProvider::class,

```

Usage
=====

[](#usage)

In your `Model` enable the trait and define `$softCascade`. [Example](https://github.com/Askedio/laravel5-soft-cascade/blob/master/tests/App/User.php).

```
use \Askedio\SoftCascade\Traits\SoftCascadeTrait;

protected $softCascade = ['profiles'];

```

For restricted relation use. [Example](https://github.com/Askedio/laravel5-soft-cascade/blob/master/tests/App/Languages.php).

```
use \Askedio\SoftCascade\Traits\SoftCascadeTrait;

protected $softCascade = ['addresses@restrict'];

```

`$softCascade` is an array of your relation names, in the [example](https://github.com/Askedio/laravel5-soft-cascade/blob/master/tests/App/User.php) you'll see we've defined `function profiles()` for the relation.

Nested relations work by defining `$softCascade` in the related `Model` as you can see [here](https://github.com/Askedio/laravel5-soft-cascade/blob/master/tests/App/Profiles.php).

After you've defined your relations you can simply trigger `delete()` or `restore()` on your `Model` and your relations will have the same task performed.

```
User::first()->delete();
User::withTrashed()->first()->restore();

```

It can also be used with query builder in this way because query builder listener is executed after query, we need to use transaction for rollback query on error due to restricted relationships

```
try {
    DB::beginTransaction(); //Start db transaction for rollback query when error
    User::limit(2)->delete();
	User::withTrashed()->limit(2)->restore();
    DB::commit(); //Commit the query
} catch (\Exception $e) {
    DB::rollBack(); //Rollback the query
    //Optional, if we need to continue execution only rollback transaction and save message on variable
    throw new \Askedio\SoftCascade\Exceptions\SoftCascadeLogicException($e->getMessage());
}

```

Supported Databases
===================

[](#supported-databases)

- MySQL
- PostgreSQL
- SQLite
- SQL Server

Testing
=======

[](#testing)

I have written some very basic tests, certainly more needs to be done here. If you find this useful please help by testing other databases or writing better unit tests because I must move on.

Issues &amp; Contributing
=========================

[](#issues--contributing)

I will be using this with MySQL in a new API so any issues I find related to my use will be resolved. If you find an issue with MySQL please report it and I will fix it.

If you are using another database and have issues please contribute by submitting a pull request. I do not have time to test this with other database but assume all would work.

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 54.3% 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 ~49 days

Recently: every ~222 days

Total

51

Last Release

1180d ago

Major Versions

5.7.5 → 6.02020-02-04

6.1.0 → 7.0.02020-09-09

7.0.0 → 8.0.02020-09-09

8.0.1 → 9.0.02022-06-24

9.0.0 → 10.0.02023-02-14

PHP version history (9 changes)1.0PHP &gt;=5.5.9

5.5.0PHP &gt;=7.0.0

5.6.0PHP &gt;=7.1.3

5.7.0PHP ^7.1.3

6.0PHP ^7.2

6.1.0PHP ^7.2.5

8.0.0PHP &gt;=7.3.0

9.0.0PHP ^7.2.5|^8.0

10.0.0PHP ^8.0

### Community

Maintainers

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

---

Top Contributors

[![maguilar92](https://avatars.githubusercontent.com/u/25102127?v=4)](https://github.com/maguilar92 "maguilar92 (121 commits)")[![gcphost](https://avatars.githubusercontent.com/u/1173636?v=4)](https://github.com/gcphost "gcphost (75 commits)")[![j-fulbright](https://avatars.githubusercontent.com/u/10793868?v=4)](https://github.com/j-fulbright "j-fulbright (6 commits)")[![Siva93-knackforge](https://avatars.githubusercontent.com/u/68694539?v=4)](https://github.com/Siva93-knackforge "Siva93-knackforge (4 commits)")[![IlCallo](https://avatars.githubusercontent.com/u/10036108?v=4)](https://github.com/IlCallo "IlCallo (4 commits)")[![Siva-93](https://avatars.githubusercontent.com/u/23162534?v=4)](https://github.com/Siva-93 "Siva-93 (3 commits)")[![abhimanyu003](https://avatars.githubusercontent.com/u/265913?v=4)](https://github.com/abhimanyu003 "abhimanyu003 (2 commits)")[![Lloople](https://avatars.githubusercontent.com/u/5665466?v=4)](https://github.com/Lloople "Lloople (1 commits)")[![mblarsen](https://avatars.githubusercontent.com/u/247048?v=4)](https://github.com/mblarsen "mblarsen (1 commits)")[![om3rcitak](https://avatars.githubusercontent.com/u/5197413?v=4)](https://github.com/om3rcitak "om3rcitak (1 commits)")[![rbruhn](https://avatars.githubusercontent.com/u/1283141?v=4)](https://github.com/rbruhn "rbruhn (1 commits)")[![gregoriohc](https://avatars.githubusercontent.com/u/566841?v=4)](https://github.com/gregoriohc "gregoriohc (1 commits)")[![Destiphy](https://avatars.githubusercontent.com/u/43512995?v=4)](https://github.com/Destiphy "Destiphy (1 commits)")[![squiaios](https://avatars.githubusercontent.com/u/13620819?v=4)](https://github.com/squiaios "squiaios (1 commits)")[![tkempf](https://avatars.githubusercontent.com/u/2909428?v=4)](https://github.com/tkempf "tkempf (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[watson/validating

Eloquent model validating trait.

9723.3M46](/packages/watson-validating)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)

PHPackages © 2026

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