From 4329fa8a7afc24b25b10aa5d8486166a8885b8b7 Mon Sep 17 00:00:00 2001 From: Ollie Read Date: Mon, 18 Nov 2024 09:50:48 +0000 Subject: [PATCH] chore: Do not apply condition from scopes when outside multitenanted context --- src/Database/Eloquent/Scopes/BelongsToManyTenantsScope.php | 5 +++++ src/Database/Eloquent/Scopes/BelongsToTenantScope.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Database/Eloquent/Scopes/BelongsToManyTenantsScope.php b/src/Database/Eloquent/Scopes/BelongsToManyTenantsScope.php index 3d23f82..0422c43 100644 --- a/src/Database/Eloquent/Scopes/BelongsToManyTenantsScope.php +++ b/src/Database/Eloquent/Scopes/BelongsToManyTenantsScope.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Sprout\Exceptions\TenantMissing; +use function Sprout\sprout; /** * Belongs to many Tenants Scope @@ -38,6 +39,10 @@ final class BelongsToManyTenantsScope extends TenantChildScope */ public function apply(Builder $builder, Model $model): void { + if (! sprout()->withinContext()) { + return; + } + /** @phpstan-ignore-next-line */ $tenancy = $model->getTenancy(); diff --git a/src/Database/Eloquent/Scopes/BelongsToTenantScope.php b/src/Database/Eloquent/Scopes/BelongsToTenantScope.php index c166ba1..b3ec890 100644 --- a/src/Database/Eloquent/Scopes/BelongsToTenantScope.php +++ b/src/Database/Eloquent/Scopes/BelongsToTenantScope.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Sprout\Exceptions\TenantMissing; +use function Sprout\sprout; /** * Belongs to Tenant Scope @@ -38,6 +39,10 @@ final class BelongsToTenantScope extends TenantChildScope */ public function apply(Builder $builder, Model $model): void { + if (! sprout()->withinContext()) { + return; + } + /** @phpstan-ignore-next-line */ $tenancy = $model->getTenancy();