Download the PHP package sofa/eloquent-cascade without Composer
On this page you can find all versions of the php package sofa/eloquent-cascade. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-cascade
Sofa/EloquentCascade
Cascading (soft / hard) deletes for the Eloquent ORM (Laravel 5.0+).
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
- using with
SoftDeletes
- CHANGELOG
Installation
Package goes along with Laravel (Illuminate) versioning, in order to make it easy for you to pick appropriate version:
Laravel / Illuminate 5.2+:
Laravel / Illuminate 5.0/5.1:
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;
$model->delete()
&$query->delete()
w/o soft deletes- when using soft deletes ensure traits order:
use SoftDeletes, CascadeDeletes
$model->delete()
&$query->delete()
with soft deletes$model->forceDelete()
BUT$query->forceDelete()
will not work
simple:
-
delete()
called on the model: delete()
called on the eloquent queryBuilder
:
using with SoftDeletes
NOTE order of using traits matters, so make sure you use SoftDeletes
before CascadeDeletes
.
-
cascade with soft deletes - every model using
SoftDeletes
gets soft deleted, others are hard deleted - cascade with
forceDelete()
called on the model will hard-delete all the relations (NOTE due to the current implementation of forceDelete in laravel core, it will not work on the Builder)
TODO
- [x] cascade
restoring
soft deleted models - [ ] detach m-m relations / delete related
- [ ] add SET NULL and RESTRICT options (?)
Contribution
All contributions are welcome, PRs must be PSR-2 compliant.
CHANGELOG
v6 <- v5.x
- Restoring now will cascade only for children that were deleted along with the parent model, not before. That is, if some of children models were soft deleted before the parent model got deleted, those children will not be restored when parent is being restored. That's the expected behavior.
- The above requires that when calling restore on the query builder rather than single model (
$query->restore()
vs$model->restore()
), it will run N queries, 1 for each restored model.