From 7900457254364fa742317ca3b218d2711bc8a331 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 7 Jul 2026 13:37:42 +0200 Subject: [PATCH] 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(). --- src/ResourceSyncing/TriggerSyncingEvents.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ResourceSyncing/TriggerSyncingEvents.php b/src/ResourceSyncing/TriggerSyncingEvents.php index dada31db..b59a9550 100644 --- a/src/ResourceSyncing/TriggerSyncingEvents.php +++ b/src/ResourceSyncing/TriggerSyncingEvents.php @@ -22,9 +22,9 @@ trait TriggerSyncingEvents public static function bootTriggerSyncingEvents(): void { 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 + // Try getting the central resource to see if it is available. + // If it is not, getCentralResourceAndTenant() throws (indirectly, via findCentralResource() -> getResourceClass()), + // interrupting the save, preventing the creation of a pivot record without a central resource. $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 { /** @var $this&Pivot $this */