mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 02:54:06 +00:00
separate pivot model for each approach
This commit is contained in:
parent
dfe1fcecb5
commit
b08961150c
4 changed files with 31 additions and 10 deletions
22
src/Database/Models/TenantMorphPivot.php
Normal file
22
src/Database/Models/TenantMorphPivot.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Database\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphPivot;
|
||||
use Stancl\Tenancy\Contracts\Syncable;
|
||||
|
||||
class TenantMorphPivot extends MorphPivot
|
||||
{
|
||||
public static function booted(): void
|
||||
{
|
||||
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