mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-07 02:44:04 +00:00
Syncing: move global ID generation logic to an overridable method
Also make all resource syncing-related listener closures static. Also correct return type for getGlobalIdentifierKey to string|int. (We intentionally do not support returning null like many other "get x key" methods would since such a case might break resource syncing logic. This is also why we use inline getAttribute() in the creating listener instead of calling the method.)
This commit is contained in:
parent
e079803025
commit
072fcc6326
3 changed files with 24 additions and 15 deletions
|
|
@ -20,14 +20,14 @@ trait TriggerSyncingEvents
|
|||
{
|
||||
public static function bootTriggerSyncingEvents(): void
|
||||
{
|
||||
static::saving(function (self $pivot) {
|
||||
static::saving(static function (self $pivot) {
|
||||
// Try getting the central resource to see if it is available
|
||||
// If it is not available, throw an exception to interrupt the saving process
|
||||
// And prevent creating a pivot record without a central resource
|
||||
$pivot->getCentralResourceAndTenant();
|
||||
});
|
||||
|
||||
static::saved(function (self $pivot) {
|
||||
static::saved(static function (self $pivot) {
|
||||
/**
|
||||
* @var static&Pivot $pivot
|
||||
* @var SyncMaster|null $centralResource
|
||||
|
|
@ -40,7 +40,7 @@ trait TriggerSyncingEvents
|
|||
}
|
||||
});
|
||||
|
||||
static::deleting(function (self $pivot) {
|
||||
static::deleting(static function (self $pivot) {
|
||||
/**
|
||||
* @var static&Pivot $pivot
|
||||
* @var SyncMaster|null $centralResource
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue