mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 07:24:05 +00:00
Merge branch 'master' into validate-sql-parameters
This commit is contained in:
commit
9055b61a04
20 changed files with 546 additions and 98 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,22 +61,11 @@ trait HasPending
|
|||
*/
|
||||
public static function createPending(array $attributes = []): Model&Tenant
|
||||
{
|
||||
$tenant = null;
|
||||
|
||||
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 PendingTenantCreated($tenant));
|
||||
|
||||
return $tenant;
|
||||
return static::create(array_merge(
|
||||
static::getPendingAttributes($attributes),
|
||||
$attributes,
|
||||
['pending_since' => now()->timestamp],
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class PendingScope implements Scope
|
|||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*
|
||||
* @param Builder<Model> $builder
|
||||
* @param Builder<covariant Model> $builder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Scope;
|
|||
class ParentModelScope implements Scope
|
||||
{
|
||||
/**
|
||||
* @param Builder<Model> $builder
|
||||
* @param Builder<covariant Model> $builder
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use Stancl\Tenancy\Tenancy;
|
|||
class TenantScope implements Scope
|
||||
{
|
||||
/**
|
||||
* @param Builder<Model> $builder
|
||||
* @param Builder<covariant Model> $builder
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue