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

Fix initialize() method

This commit is contained in:
Samuel Štancl 2020-09-04 12:42:08 +02:00
parent 375380cc7e
commit 2cd00a5b77

View file

@ -31,6 +31,16 @@ class Tenancy
*/
public function initialize($tenant): void
{
if (! is_object($tenant)) {
$tenant = $tenant;
$tenantId = $tenant;
$tenant = $this->find($tenantId);
if (! $tenant) {
throw new TenantCountNotBeIdentifiedById($tenantId);
}
}
if ($this->initialized && $this->tenant->getTenantKey() === $tenant->getTenantKey()) {
return;
}
@ -40,18 +50,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));