1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 11:14:03 +00:00

add pullPendingTenantFromPool

This commit is contained in:
Samuel Štancl 2022-10-18 13:39:02 +02:00 committed by GitHub
parent e93a5181c3
commit 090fc475eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,6 +49,7 @@ trait HasPending
return ! is_null($this->pending_since); return ! is_null($this->pending_since);
} }
/** Create a pending tenant. */
public static function createPending($attributes = []): Tenant public static function createPending($attributes = []): Tenant
{ {
$tenant = static::create($attributes); $tenant = static::create($attributes);
@ -66,12 +67,20 @@ trait HasPending
return $tenant; return $tenant;
} }
public static function pullPendingTenant(bool $firstOrCreate = false): ?Tenant /** Pull a pending tenant. */
public static function pullPendingTenant(): Tenant
{
return static::pullPendingTenantFromPool(true);
}
/** Try to pull a tenant from the pool of pending tenants. */
public static function pullPendingTenantFromPool(bool $firstOrCreate = false): ?Tenant
{ {
if (! static::onlyPending()->exists()) { if (! static::onlyPending()->exists()) {
if (! $firstOrCreate) { if (! $firstOrCreate) {
return null; return null;
} }
static::createPending(); static::createPending();
} }