You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
529 B
PHTML
22 lines
529 B
PHTML
2 years ago
|
<?php
|
||
|
|
||
|
namespace App\Models\Traits;
|
||
|
|
||
|
trait CascadeSoftDeletes
|
||
|
{
|
||
|
protected static function bootCascadeSoftDeletes()
|
||
|
{
|
||
|
static::deleting(function ($resource) {
|
||
|
foreach ($resource->cascadeDeletes as $relation) {
|
||
|
$resource->{$relation}()->delete();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
static::restoring(function ($resource) {
|
||
|
foreach ($resource->cascadeDeletes as $relation) {
|
||
|
$resource->{$relation}()->withTrashed()->restore();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|