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

Dispatch pending tenant creating/created events in the appropriate hooks

This commit is contained in:
lukinovec 2026-04-28 12:28:31 +02:00
parent 0bb112dbdf
commit e3673f5557

View file

@ -28,6 +28,18 @@ trait HasPending
public static function bootHasPending(): void public static function bootHasPending(): void
{ {
static::addGlobalScope(new PendingScope()); 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. */ /** Initialize the trait. */
@ -49,19 +61,11 @@ trait HasPending
*/ */
public static function createPending(array $attributes = []): Model&Tenant public static function createPending(array $attributes = []): Model&Tenant
{ {
$tenant = static::make(array_merge( return static::create(array_merge(
['pending_since' => now()->timestamp], ['pending_since' => now()->timestamp],
static::getPendingAttributes($attributes), static::getPendingAttributes($attributes),
$attributes $attributes
)); ));
event(new CreatingPendingTenant($tenant));
$tenant->save();
event(new PendingTenantCreated($tenant));
return $tenant;
} }
/** /**