mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 01:14:03 +00:00
Universal routes
This commit is contained in:
parent
7bc58f3980
commit
70b869c43f
1 changed files with 9 additions and 4 deletions
|
|
@ -22,12 +22,17 @@ class PreventAccessFromTenantDomains
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
|
// If the route is universal, always let the request pass.
|
||||||
|
if ($this->routeHasMiddleware($request()->route(), 'universal')) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
// If the domain is not in exempt domains, it's a tenant domain.
|
// If the domain is not in exempt domains, it's a tenant domain.
|
||||||
// Tenant domains can't have routes without tenancy middleware.
|
// Tenant domains can't have routes without tenancy middleware.
|
||||||
$isExemptDomain = in_array($request->getHost(), config('tenancy.exempt_domains'));
|
$isExemptDomain = in_array($request->getHost(), config('tenancy.exempt_domains'));
|
||||||
$isTenantDomain = ! $isExemptDomain;
|
$isTenantDomain = ! $isExemptDomain;
|
||||||
|
|
||||||
$isTenantRoute = $this->isTenantRoute($request->route());
|
$isTenantRoute = $this->routeHasMiddleware($request->route(), 'tenancy');
|
||||||
|
|
||||||
if ($isTenantDomain && ! $isTenantRoute) { // accessing web routes from tenant domains
|
if ($isTenantDomain && ! $isTenantRoute) { // accessing web routes from tenant domains
|
||||||
return redirect(config('tenancy.home_url'));
|
return redirect(config('tenancy.home_url'));
|
||||||
|
|
@ -40,9 +45,9 @@ class PreventAccessFromTenantDomains
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTenantRoute(Route $route): bool
|
public function routeHasMiddleware(Route $route, $middleware): bool
|
||||||
{
|
{
|
||||||
if (in_array('tenancy', $route->middleware(), true)) {
|
if (in_array($middleware, $route->middleware(), true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +55,7 @@ class PreventAccessFromTenantDomains
|
||||||
// groups have a `tenancy` middleware group inside them
|
// groups have a `tenancy` middleware group inside them
|
||||||
$middlewareGroups = Router::getMiddlewareGroups();
|
$middlewareGroups = Router::getMiddlewareGroups();
|
||||||
foreach ($route->gatherMiddleware() as $middleware) {
|
foreach ($route->gatherMiddleware() as $middleware) {
|
||||||
if (isset($middlewareGroups[$middleware]) && in_array('tenancy', $middlewareGroups[$middleware], true)) {
|
if (isset($middlewareGroups[$middleware]) && in_array($middleware, $middlewareGroups[$middleware], true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue