makeSubdomain($request->getHost()); if (is_object($subdomain) && $subdomain instanceof Exception) { $onFail = static::$onFail ?? function ($e) { throw $e; }; return $onFail($subdomain, $request, $next); } // If a Response instance was returned, we return it immediately. if (is_object($subdomain) && $subdomain instanceof Response) { return $subdomain; } return $this->initializeTenancy( $request, $next, $subdomain ); } /** @return string|Response|Exception|mixed */ protected function makeSubdomain(string $hostname) { $parts = explode('.', $hostname); $isLocalhost = count($parts) === 1; $isIpAddress = count(array_filter($parts, 'is_numeric')) === count($parts); // If we're on localhost or an IP address, then we're not visiting a subdomain. $isACentralDomain = in_array($hostname, config('tenancy.central_domains'), true); $notADomain = $isLocalhost || $isIpAddress; $thirdPartyDomain = ! Str::endsWith($hostname, config('tenancy.central_domains')); if ($isACentralDomain || $notADomain || $thirdPartyDomain) { return new NotASubdomainException($hostname); } return $parts[static::$subdomainIndex]; } }