getRoute($request); if ($this->shouldBeSkipped($route)) { return $next($request); } if ($this->accessingTenantRouteFromCentralDomain($request, $route) || $this->accessingCentralRouteFromTenantDomain($request, $route)) { $abortRequest = static::$abortRequest ?? function () { abort(404); }; return $abortRequest($request, $next); } return $next($request); } protected function accessingTenantRouteFromCentralDomain(Request $request, Route $route): bool { return tenancy()->getRouteMode($route) === RouteMode::TENANT // Current route's middleware context is tenant && $this->isCentralDomain($request); // The request comes from a domain that IS present in the configured `tenancy.identification.central_domains` } protected function accessingCentralRouteFromTenantDomain(Request $request, Route $route): bool { return tenancy()->getRouteMode($route) === RouteMode::CENTRAL // Current route's middleware context is central && ! $this->isCentralDomain($request); // The request comes from a domain that ISN'T present in the configured `tenancy.identification.central_domains` } /** * Check if the request's host name is present in the configured `tenancy.identification.central_domains`. */ protected function isCentralDomain(Request $request): bool { return in_array($request->getHost(), config('tenancy.identification.central_domains'), true); } public function requestHasTenant(Request $request): bool { // This middleware is special in that it's not an identification middleware // but still uses some logic from UsableWithEarlyIdentification, so we just // need to implement this method here. It doesn't matter what it returns. return false; } }