added events for relationships #nka5y8 #2181
This commit is contained in:
parent
8f32f37f69
commit
3c55dfdac4
20
app/Events/Common/RelationshipCounting.php
Normal file
20
app/Events/Common/RelationshipCounting.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class RelationshipCounting extends Event
|
||||
{
|
||||
public $record;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $record
|
||||
*/
|
||||
public function __construct($record)
|
||||
{
|
||||
$this->record = $record;
|
||||
}
|
||||
}
|
20
app/Events/Common/RelationshipDeleting.php
Normal file
20
app/Events/Common/RelationshipDeleting.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class RelationshipDeleting extends Event
|
||||
{
|
||||
public $record;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $record
|
||||
*/
|
||||
public function __construct($record)
|
||||
{
|
||||
$this->record = $record;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user