From b592d3dad43384c1e677a0c1e1ba9b4d50c097cd Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 28 Apr 2026 10:51:15 +0200 Subject: [PATCH] Give pending_since to pending tenants during creation Instead of creating pending tenants without pending_since, letting job pipelines (e.g. TenantCreated) run, and only after that, setting the tenant's pending_since, set it while creating. This allows checking tenant's pending status accurately e.g. in the CreateDatabase job pipeline. --- src/Database/Concerns/HasPending.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Database/Concerns/HasPending.php b/src/Database/Concerns/HasPending.php index 0a572680..312f9dea 100644 --- a/src/Database/Concerns/HasPending.php +++ b/src/Database/Concerns/HasPending.php @@ -49,18 +49,15 @@ trait HasPending */ public static function createPending(array $attributes = []): Model&Tenant { - $tenant = null; + $tenant = static::make(array_merge( + ['pending_since' => now()->timestamp], + static::getPendingAttributes($attributes), + $attributes + )); - try { - $tenant = static::create(array_merge(static::getPendingAttributes($attributes), $attributes)); - event(new CreatingPendingTenant($tenant)); - } finally { - // Update the pending_since value only after the tenant is created so it's - // not marked as pending until after migrations, seeders, etc are run. - $tenant?->update([ - 'pending_since' => now()->timestamp, - ]); - } + event(new CreatingPendingTenant($tenant)); + + $tenant->save(); event(new PendingTenantCreated($tenant));