From 89f2d724f0fe38c84a8d92edf83e45c2fe49b79f Mon Sep 17 00:00:00 2001 From: pjeutr Date: Tue, 19 Mar 2019 11:16:03 +0100 Subject: [PATCH] Allow for multiple Tenant ID's to be included Fix for multiple tenants - https://github.com/hipsterjazzbo/Landlord/pull/86/ Allow for multiple Tenant ID's to be included - https://github.com/HipsterJazzbo/Landlord/pull/53 --- src/TenantManager.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/TenantManager.php b/src/TenantManager.php index 9485621..279f5e0 100644 --- a/src/TenantManager.php +++ b/src/TenantManager.php @@ -146,11 +146,14 @@ public function applyTenantScopes(Model $model) $this->modelTenants($model)->each(function ($id, $tenant) use ($model) { $model->addGlobalScope($tenant, function (Builder $builder) use ($tenant, $id, $model) { - if ($this->getTenants()->first() && $this->getTenants()->first() != $id) { - $id = $this->getTenants()->first(); + // Fix for multiple tenants - https://github.com/hipsterjazzbo/Landlord/pull/86/ + // Allow for multiple Tenant ID's to be included - https://github.com/HipsterJazzbo/Landlord/pull/53 + $id = $this->getTenantId($tenant); + if (is_array($id)) { + $builder->whereIn($model->getQualifiedTenant($tenant), $id); + } else { + $builder->where($model->getQualifiedTenant($tenant), '=', $id); } - - $builder->where($model->getQualifiedTenant($tenant), '=', $id); }); }); } @@ -168,11 +171,14 @@ public function applyTenantScopesToDeferredModels() } $model->addGlobalScope($tenant, function (Builder $builder) use ($tenant, $id, $model) { - if ($this->getTenants()->first() && $this->getTenants()->first() != $id) { - $id = $this->getTenants()->first(); + // Fix for multiple tenants - https://github.com/hipsterjazzbo/Landlord/pull/86/ + // Allow for multiple Tenant ID's to be included - https://github.com/HipsterJazzbo/Landlord/pull/53 + $id = $this->getTenantId($tenant); + if (is_array($id)) { + $builder->whereIn($model->getQualifiedTenant($tenant), $id); + } else { + $builder->where($model->getQualifiedTenant($tenant), '=', $id); } - - $builder->where($model->getQualifiedTenant($tenant), '=', $id); }); }); });