1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:14:04 +00:00

Fix initialize() method (#488)

* Fix initialize() method

* Remove useless line
This commit is contained in:
Samuel Štancl 2020-09-08 21:19:39 +02:00 committed by GitHub
parent 36aabb7883
commit 5fe79fea33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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