mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 14:24:04 +00:00
Dispatch pending tenant creating/created events in the appropriate hooks
This commit is contained in:
parent
0bb112dbdf
commit
e3673f5557
1 changed files with 13 additions and 9 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue