diff --git a/app/Events/Common/RelationshipCounting.php b/app/Events/Common/RelationshipCounting.php new file mode 100644 index 000000000..de6be494c --- /dev/null +++ b/app/Events/Common/RelationshipCounting.php @@ -0,0 +1,20 @@ +record = $record; + } +} diff --git a/app/Events/Common/RelationshipDeleting.php b/app/Events/Common/RelationshipDeleting.php new file mode 100644 index 000000000..1d0617919 --- /dev/null +++ b/app/Events/Common/RelationshipDeleting.php @@ -0,0 +1,20 @@ +record = $record; + } +} diff --git a/app/Traits/Relationships.php b/app/Traits/Relationships.php index 2bfd36aa4..cad0692d8 100644 --- a/app/Traits/Relationships.php +++ b/app/Traits/Relationships.php @@ -2,6 +2,8 @@ namespace App\Traits; +use App\Events\Common\RelationshipCounting; +use App\Events\Common\RelationshipDeleting; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Str; @@ -9,6 +11,12 @@ trait Relationships { public function countRelationships($model, $relationships) { + $record = new \stdClass(); + $record->model = $model; + $record->relationships = $relationships; + + event(new RelationshipCounting($record)); + $counter = []; foreach ($relationships as $relationship => $text) { @@ -33,6 +41,12 @@ trait Relationships */ public function deleteRelationships($model, $relationships) { + $record = new \stdClass(); + $record->model = $model; + $record->relationships = $relationships; + + event(new RelationshipDeleting($record)); + foreach ((array) $relationships as $relationship) { if (empty($model->$relationship)) { continue;