diff --git a/src/Tenancy.php b/src/Tenancy.php index 0e80221a..307f818f 100644 --- a/src/Tenancy.php +++ b/src/Tenancy.php @@ -31,6 +31,15 @@ class Tenancy */ public function initialize($tenant): void { + if (! is_object($tenant)) { + $tenantId = $tenant; + $tenant = $this->find($tenantId); + + if (! $tenant) { + throw new TenantCountNotBeIdentifiedById($tenantId); + } + } + if ($this->initialized && $this->tenant->getTenantKey() === $tenant->getTenantKey()) { return; } @@ -40,18 +49,7 @@ class Tenancy $this->end(); } - if (is_object($tenant)) { - $this->tenant = $tenant; - } else { - $tenantId = $tenant; - $tenant = $this->find($tenantId); - - if (! $tenant) { - throw new TenantCountNotBeIdentifiedById($tenantId); - } - - $this->tenant = $tenant; - } + $this->tenant = $tenant; event(new Events\InitializingTenancy($this));