From 090fc475ebfbcd370b6d589635234cfdbca83a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 18 Oct 2022 13:39:02 +0200 Subject: [PATCH] add pullPendingTenantFromPool --- src/Database/Concerns/HasPending.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Database/Concerns/HasPending.php b/src/Database/Concerns/HasPending.php index 8baaaf77..e0c76990 100644 --- a/src/Database/Concerns/HasPending.php +++ b/src/Database/Concerns/HasPending.php @@ -49,6 +49,7 @@ trait HasPending return ! is_null($this->pending_since); } + /** Create a pending tenant. */ public static function createPending($attributes = []): Tenant { $tenant = static::create($attributes); @@ -66,12 +67,20 @@ trait HasPending 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 (! $firstOrCreate) { return null; } + static::createPending(); }