diff --git a/src/Middleware/InitializeTenancy.php b/src/Middleware/InitializeTenancy.php index 59a2fc40..6dac54b8 100644 --- a/src/Middleware/InitializeTenancy.php +++ b/src/Middleware/InitializeTenancy.php @@ -8,7 +8,9 @@ class InitializeTenancy { public function __construct(Closure $onFail = null) { - $this->onFail = $onFail ?: function ($e) { throw $e; }; + $this->onFail = $onFail ?: function ($e) { + throw $e; + }; } /** @@ -20,8 +22,12 @@ class InitializeTenancy */ public function handle($request, Closure $next) { + if (in_array($request->getHost(), config('tenancy.exempt_domains', []))) { + return $next($request); + } + try { - tenancy()->init(); + tenancy()->init(); } catch (\Exception $e) { // Pass the exception to the onFail function if it takes any parameters. $callback = $this->onFail; diff --git a/src/config/tenancy.php b/src/config/tenancy.php index 4c2ce2bc..00e4b79c 100644 --- a/src/config/tenancy.php +++ b/src/config/tenancy.php @@ -2,6 +2,9 @@ return [ 'storage_driver' => 'Stancl\Tenancy\StorageDrivers\RedisStorageDriver', + 'exempt_domains' => [ + // 'localhost', + ], 'database' => [ 'based_on' => 'mysql', 'prefix' => 'tenant',