1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 11:04:04 +00:00

Clarify how the pivot saving listener throws

The comment said an exception is thrown but not how -- it happens
indirectly via findCentralResource() -> getResourceClass(). Also added a @throws annotation to getCentralResourceAndTenant().
This commit is contained in:
lukinovec 2026-07-07 13:37:42 +02:00
parent d2fb4bc0d5
commit 7900457254

View file

@ -22,9 +22,9 @@ trait TriggerSyncingEvents
public static function bootTriggerSyncingEvents(): void public static function bootTriggerSyncingEvents(): void
{ {
static::saving(static function (self $pivot) { static::saving(static function (self $pivot) {
// Try getting the central resource to see if it is available // Try getting the central resource to see if it is available.
// If it is not available, throw an exception to interrupt the saving process // If it is not, getCentralResourceAndTenant() throws (indirectly, via findCentralResource() -> getResourceClass()),
// And prevent creating a pivot record without a central resource // interrupting the save, preventing the creation of a pivot record without a central resource.
$pivot->getCentralResourceAndTenant(); $pivot->getCentralResourceAndTenant();
}); });
@ -56,6 +56,10 @@ trait TriggerSyncingEvents
}); });
} }
/**
* @throws CentralResourceNotAvailableInPivotException Throws when the tenant is the pivot parent
* but the central resource class cannot be resolved (thrown indirectly via findCentralResource() -> getResourceClass())
*/
public function getCentralResourceAndTenant(): array public function getCentralResourceAndTenant(): array
{ {
/** @var $this&Pivot $this */ /** @var $this&Pivot $this */