PHPackages                             sofa/eloquent-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. sofa/eloquent-cascade

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

sofa/eloquent-cascade
=====================

Cascading deletes for Laravel Eloquent ORM.

v6.1.1(4y ago)2410.1k3MITPHPPHP &gt;=7.2.5

Since May 31Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jarektkaczyk/eloquent-cascade)[ Packagist](https://packagist.org/packages/sofa/eloquent-cascade)[ Fund](https://softonsofa.com)[ GitHub Sponsors](https://github.com/jarektkaczyk)[ RSS](/packages/sofa-eloquent-cascade/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (1)Versions (16)Used By (0)

Sofa/EloquentCascade
====================

[](#sofaeloquentcascade)

[![Downloads](https://camo.githubusercontent.com/e0f64b93873471a057febc562c6e622206bd2a19d4bc9e7025eea346d1cb1381/68747470733a2f2f706f7365722e707567782e6f72672f736f66612f656c6f7175656e742d636173636164652f646f776e6c6f616473)](https://packagist.org/packages/sofa/eloquent-cascade) [![stable](https://camo.githubusercontent.com/d3980cc90531c1ac8fdf5d5b82ab1f1931aa76e7e60e531892d3ae8f49088bc0/68747470733a2f2f706f7365722e707567782e6f72672f736f66612f656c6f7175656e742d636173636164652f762f737461626c652e737667)](https://packagist.org/packages/sofa/eloquent-cascade)

Cascading (soft / hard) deletes for the [Eloquent ORM (Laravel 5.0+)](https://laravel.com/docs/eloquent).

**Why use this one?** There are couple of packages that already provide cascading deletes for eloquent, but none of them works with the query builder. Here you get support for both `$model->delete()` and `$query->delete()`, as well as `$model->forceDelete()`.

- [simple usage](#simple)
- [using with `SoftDeletes`](#using-with-softdeletes)
- [CHANGELOG](#changelog)

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

[](#installation)

Package goes along with Laravel (Illuminate) versioning, in order to make it easy for you to pick appropriate version:

Laravel / Illuminate **5.2+**:

```
composer require sofa/eloquent-cascade:"~5.2"

```

Laravel / Illuminate **5.0/5.1**:

```
composer require sofa/eloquent-cascade:"~5.1"

```

Usage
-----

[](#usage)

Use provided `CascadeDeletes` trait in your model and define relation to be deleted in cascade. Related models will be deleted automatically and appropriately, that is either `hard` or `soft` deleted, depending on the related model settings and delete method used:

#### tldr;

[](#tldr)

1. `$model->delete()` &amp; `$query->delete()` w/o soft deletes
2. when using soft deletes ensure traits order: `use SoftDeletes, CascadeDeletes`
3. `$model->delete()` &amp; `$query->delete()` with soft deletes
4. `$model->forceDelete()` **BUT `$query->forceDelete()` will not work**

#### simple:

[](#simple)

```
