PHPackages                             askedio/laravel5-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. askedio/laravel5-soft-cascade

ActiveLibrary

askedio/laravel5-soft-cascade
=============================

Laravel Cascade Soft Delete &amp; Restore

12.0.0(1y ago)71397.1k↓33.5%63[10 issues](https://github.com/Askedio/laravel-soft-cascade/issues)[1 PRs](https://github.com/Askedio/laravel-soft-cascade/pulls)MITPHPPHP ^8.2CI passing

Since May 2Pushed 2mo ago13 watchersCompare

[ Source](https://github.com/Askedio/laravel-soft-cascade)[ Packagist](https://packagist.org/packages/askedio/laravel5-soft-cascade)[ RSS](/packages/askedio-laravel5-soft-cascade/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (73)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.

Why 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

64

—

FairBetter than 99% of packages

Maintenance66

Regular maintenance activity

Popularity54

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

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

Recently: every ~31 days

Total

66

Last Release

448d ago

Major Versions

7.0.x-dev → 8.0.02020-09-21

8.0.x-dev → 9.0.02022-02-15

9.0.x-dev → 10.0.02023-02-17

10.0.x-dev → 11.0.02024-03-14

11.0.x-dev → 12.0.02025-02-24

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

5.5.0PHP &gt;=7.0.0

5.6.0PHP &gt;=7.1.3

5.7.x-devPHP ^7.1.3

6.0.0PHP ^7.2

7.0.0PHP ^7.2.5

8.1.0PHP ^7.2.5|^8.0

11.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1173636?v=4)[William](/maintainers/gcphost)[@gcphost](https://github.com/gcphost)

---

Top Contributors

[![maguilar92](https://avatars.githubusercontent.com/u/25102127?v=4)](https://github.com/maguilar92 "maguilar92 (124 commits)")[![gcphost](https://avatars.githubusercontent.com/u/1173636?v=4)](https://github.com/gcphost "gcphost (89 commits)")[![AlwinGarside](https://avatars.githubusercontent.com/u/193043?v=4)](https://github.com/AlwinGarside "AlwinGarside (10 commits)")[![kohlerdominik](https://avatars.githubusercontent.com/u/18621527?v=4)](https://github.com/kohlerdominik "kohlerdominik (7 commits)")[![ysfks](https://avatars.githubusercontent.com/u/10243325?v=4)](https://github.com/ysfks "ysfks (6 commits)")[![IlCallo](https://avatars.githubusercontent.com/u/10036108?v=4)](https://github.com/IlCallo "IlCallo (4 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![abhimanyu003](https://avatars.githubusercontent.com/u/265913?v=4)](https://github.com/abhimanyu003 "abhimanyu003 (2 commits)")[![faustbrian](https://avatars.githubusercontent.com/u/22145591?v=4)](https://github.com/faustbrian "faustbrian (1 commits)")[![Destiphy](https://avatars.githubusercontent.com/u/43512995?v=4)](https://github.com/Destiphy "Destiphy (1 commits)")[![ckbaker10](https://avatars.githubusercontent.com/u/56784875?v=4)](https://github.com/ckbaker10 "ckbaker10 (1 commits)")[![Lloople](https://avatars.githubusercontent.com/u/5665466?v=4)](https://github.com/Lloople "Lloople (1 commits)")[![coziboy](https://avatars.githubusercontent.com/u/5995095?v=4)](https://github.com/coziboy "coziboy (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)")[![perstnev](https://avatars.githubusercontent.com/u/61965829?v=4)](https://github.com/perstnev "perstnev (1 commits)")[![rbruhn](https://avatars.githubusercontent.com/u/1283141?v=4)](https://github.com/rbruhn "rbruhn (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)")[![gregoriohc](https://avatars.githubusercontent.com/u/566841?v=4)](https://github.com/gregoriohc "gregoriohc (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/askedio-laravel5-soft-cascade/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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