mirror of
https://github.com/archtechx/tenancy.git
synced 2026-03-22 13:14:03 +00:00
Merge branch 'sync' of https://github.com/leandrogehlen/tenancy into 3.x
This commit is contained in:
commit
d34a6dcd7d
4 changed files with 80 additions and 7 deletions
|
|
@ -15,4 +15,6 @@ interface Syncable
|
|||
public function getSyncedAttributeNames(): array;
|
||||
|
||||
public function triggerSyncEvent();
|
||||
|
||||
public function isSyncEnabled();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,15 +14,16 @@ trait ResourceSyncing
|
|||
{
|
||||
static::saved(function (Syncable $model) {
|
||||
/** @var ResourceSyncing $model */
|
||||
$model->triggerSyncEvent();
|
||||
if ($model->isSyncEnabled()) {
|
||||
$model->triggerSyncEvent();
|
||||
}
|
||||
});
|
||||
|
||||
static::creating(function (self $model) {
|
||||
if (! $model->getAttribute($model->getGlobalIdentifierKeyName()) && app()->bound(UniqueIdentifierGenerator::class)) {
|
||||
$model->setAttribute(
|
||||
$model->getGlobalIdentifierKeyName(),
|
||||
app(UniqueIdentifierGenerator::class)->generate($model)
|
||||
);
|
||||
$keyName = $model->getGlobalIdentifierKeyName();
|
||||
|
||||
if (! $model->getAttribute($keyName) && app()->bound(UniqueIdentifierGenerator::class)) {
|
||||
$model->setAttribute($keyName, app(UniqueIdentifierGenerator::class)->generate($model));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -32,4 +33,9 @@ trait ResourceSyncing
|
|||
/** @var Syncable $this */
|
||||
event(new SyncedResourceSaved($this, tenant()));
|
||||
}
|
||||
|
||||
public function isSyncEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class TenantPivot extends Pivot
|
|||
static::saved(function (self $pivot) {
|
||||
$parent = $pivot->pivotParent;
|
||||
|
||||
if ($parent instanceof Syncable) {
|
||||
if ($parent instanceof Syncable && $parent->isSyncEnabled()) {
|
||||
$parent->triggerSyncEvent();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue