From e3673f5557bfb2efd4a7b60cea2eb8673e817f14 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 28 Apr 2026 12:28:31 +0200 Subject: [PATCH] Dispatch pending tenant creating/created events in the appropriate hooks --- src/Database/Concerns/HasPending.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Database/Concerns/HasPending.php b/src/Database/Concerns/HasPending.php index 312f9dea..03fdc26b 100644 --- a/src/Database/Concerns/HasPending.php +++ b/src/Database/Concerns/HasPending.php @@ -28,6 +28,18 @@ trait HasPending public static function bootHasPending(): void { static::addGlobalScope(new PendingScope()); + + static::creating(function (self $tenant): void { + if ($tenant->pending()) { + event(new CreatingPendingTenant($tenant)); + } + }); + + static::created(function (self $tenant): void { + if ($tenant->pending()) { + event(new PendingTenantCreated($tenant)); + } + }); } /** Initialize the trait. */ @@ -49,19 +61,11 @@ trait HasPending */ public static function createPending(array $attributes = []): Model&Tenant { - $tenant = static::make(array_merge( + return static::create(array_merge( ['pending_since' => now()->timestamp], static::getPendingAttributes($attributes), $attributes )); - - event(new CreatingPendingTenant($tenant)); - - $tenant->save(); - - event(new PendingTenantCreated($tenant)); - - return $tenant; } /**