mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 23:54:04 +00:00
27 lines
718 B
PHP
27 lines
718 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class InitializeTenancyByDomainOrSubdomain
|
|
{
|
|
/** @return \Illuminate\Http\Response|mixed */
|
|
public function handle(Request $request, Closure $next): mixed
|
|
{
|
|
if ($this->isSubdomain($request->getHost())) {
|
|
return app(InitializeTenancyBySubdomain::class)->handle($request, $next);
|
|
} else {
|
|
return app(InitializeTenancyByDomain::class)->handle($request, $next);
|
|
}
|
|
}
|
|
|
|
protected function isSubdomain(string $hostname): bool
|
|
{
|
|
return Str::endsWith($hostname, config('tenancy.central_domains'));
|
|
}
|
|
}
|