1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 16:24:03 +00:00

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.
This commit is contained in:
lukinovec 2026-04-28 10:51:15 +02:00
parent 6b4d22bb92
commit b592d3dad4

View file

@ -49,18 +49,15 @@ trait HasPending
*/ */
public static function createPending(array $attributes = []): Model&Tenant public static function createPending(array $attributes = []): Model&Tenant
{ {
$tenant = null; $tenant = static::make(array_merge(
['pending_since' => now()->timestamp],
static::getPendingAttributes($attributes),
$attributes
));
try { event(new CreatingPendingTenant($tenant));
$tenant = static::create(array_merge(static::getPendingAttributes($attributes), $attributes));
event(new CreatingPendingTenant($tenant)); $tenant->save();
} 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 PendingTenantCreated($tenant)); event(new PendingTenantCreated($tenant));