1
0
Fork 0
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:
Samuel Stancl 2026-06-07 14:17:28 -07:00 committed by GitHub
commit 9055b61a04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 546 additions and 98 deletions

View file

@ -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],
));
}
/**

View file

@ -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
*/

View file

@ -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
{

View file

@ -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)
{