mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:34:04 +00:00
trait
This commit is contained in:
parent
306a0a7204
commit
b99fcc28fd
3 changed files with 25 additions and 22 deletions
21
src/Database/Concerns/TriggerSyncEvent.php
Normal file
21
src/Database/Concerns/TriggerSyncEvent.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Database\Concerns;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Contracts\Syncable;
|
||||||
|
|
||||||
|
trait TriggerSyncEvent
|
||||||
|
{
|
||||||
|
public static function booted(): void
|
||||||
|
{
|
||||||
|
static::saved(function (self $pivot) {
|
||||||
|
$parent = $pivot->pivotParent;
|
||||||
|
|
||||||
|
if ($parent instanceof Syncable && $parent->shouldSync()) {
|
||||||
|
$parent->triggerSyncEvent();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,18 +5,9 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Database\Models;
|
namespace Stancl\Tenancy\Database\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphPivot;
|
use Illuminate\Database\Eloquent\Relations\MorphPivot;
|
||||||
use Stancl\Tenancy\Contracts\Syncable;
|
use Stancl\Tenancy\Database\Concerns\TriggerSyncEvent;
|
||||||
|
|
||||||
class TenantMorphPivot extends MorphPivot
|
class TenantMorphPivot extends MorphPivot
|
||||||
{
|
{
|
||||||
public static function booted(): void
|
use TriggerSyncEvent;
|
||||||
{
|
|
||||||
static::saved(function (self $pivot) {
|
|
||||||
$parent = $pivot->pivotParent;
|
|
||||||
|
|
||||||
if ($parent instanceof Syncable && $parent->shouldSync()) {
|
|
||||||
$parent->triggerSyncEvent();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,9 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Database\Models;
|
namespace Stancl\Tenancy\Database\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||||
use Stancl\Tenancy\Contracts\Syncable;
|
use Stancl\Tenancy\Database\Concerns\TriggerSyncEvent;
|
||||||
|
|
||||||
class TenantPivot extends Pivot
|
class TenantPivot extends Pivot
|
||||||
{
|
{
|
||||||
public static function booted(): void
|
use TriggerSyncEvent;
|
||||||
{
|
|
||||||
static::saved(function (self $pivot) {
|
|
||||||
$parent = $pivot->pivotParent;
|
|
||||||
|
|
||||||
if ($parent instanceof Syncable && $parent->shouldSync()) {
|
|
||||||
$parent->triggerSyncEvent();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue