Skip to content

Commit c2c6a55

Browse files
committed
Refactor method used to resolve tenant and update its implementation in SetTenant middleware to reflect changes
1 parent efcd120 commit c2c6a55

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/Http/Middleware/SetTenant.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public function handle($request, Closure $next, $guard = null)
3131

3232
$subdomainSafeRoutes = tenancy()->config()->getOption('routes.subdomain_safe_routes');
3333

34-
$subomainSafeCheck = empty($subdomainSafeRoutes) ? false : $request->routeIs($subdomainSafeRoutes);
34+
$subdomainSafeCheck = empty($subdomainSafeRoutes) ? false : $request->routeIs($subdomainSafeRoutes);
3535

36-
if (tenancy()->config()->getOption('routes.subdomain') && empty($subomainSafeCheck)) {
36+
if (tenancy()->config()->getOption('routes.subdomain') && empty($subdomainSafeCheck)) {
3737
$value = ($request->{$subdomainKey});
3838
} else {
3939
$value = $inHeader ? $request->header(TenantStore::TENANT_HEADER) : tenancy()->store()->getKey($request->{$paramKey});
4040
}
4141

42-
$tenant = tenancy()->resolveTenant($value);
42+
$tenant = tenancy()->resolveTenant($value, $subdomainSafeCheck);
4343

4444
if (!$tenant) {
4545
return config('tenancy.redirect.abort') ? abort(404) : redirect(config('tenancy.redirect.fallback_url'));

src/Tenancy.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,43 @@ public function store()
7070
return new TenantStore();
7171
}
7272

73+
/**
74+
* Get subdomain safe routes list.
75+
*
76+
* @return array|null
77+
*/
78+
public function subdomainSafeRoutes()
79+
{
80+
return tenancy()->config()->getOption('routes.subdomain_safe_routes');
81+
}
82+
83+
/**
84+
* Determine if current route is a non-tenant based subdomain.
85+
*
86+
* @return bool
87+
*/
88+
public function subdomainSafeCheck()
89+
{
90+
$subdomainSafeRoutes = $this->subdomainSafeRoutes();
91+
92+
return empty($subdomainSafeRoutes) ? false : request()->routeIs($subdomainSafeRoutes);
93+
}
94+
7395
/**
7496
* Resolve the tenant.
7597
*
76-
* @param $value
77-
* @return mixed
98+
* @param int|string $value
99+
* @param bool $ignoreSubdomainCheck
100+
* @return \Illuminate\Database\Eloquent\Model|null
78101
*/
79-
public function resolveTenant($value, $ignoreSubdomain = false)
102+
public function resolveTenant($value, $ignoreSubdomainCheck = false)
80103
{
81104
$model = $this->tenantModel();
82105

83-
if (tenancy()->config()->getOption('routes.subdomain') && $ignoreSubdomain == false) {
106+
if (tenancy()->config()->getOption('routes.subdomain') && $ignoreSubdomainCheck == false) {
84107
$key = tenancy()->config()->getOption('routes.subdomain_key', 'domain');
85108
} else {
86-
$key = (tenancy()->config()->storeDriver() === 'db') ? config('tenancy.model.db_key') : config('tenancy.model.key');
109+
$key = $this->getTenantDriverStoreKey();
87110
}
88111

89112
return $model->where($key, $value)->first();

0 commit comments

Comments
 (0)