makeSubdomain($request->getHost()); // If a non-string, like a Response instance was returned // from makeSubdomain() - due to NotASubDomainException // being thrown, we abort by returning the value now. if (! is_string($subdomain)) { return $subdomain; } return $this->initializeTenancy( $request, $next, $subdomain ); } /** @return string|Response|mixed */ protected function makeSubdomain(string $hostname) { $parts = explode('.', $hostname); // If we're on localhost or an IP address, then we're not visiting a subdomain. $notADomain = in_array(count($parts), [1, 4]); $thirdPartyDomain = ! Str::endsWith($hostname, config('tenancy.central_domains'));; if ($notADomain || $thirdPartyDomain) { $handle = static::$onInvalidSubdomain ?? function ($e) { throw $e; }; return $handle(new NotASubdomainException($hostname)); } return $parts[static::$subdomainIndex]; } }