mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
Combined subdomain/domain identification
This commit is contained in:
parent
8ea4940f34
commit
f328fc9c08
4 changed files with 141 additions and 4 deletions
32
src/Middleware/InitializeTenancyByDomainOrSubdomain.php
Normal file
32
src/Middleware/InitializeTenancyByDomainOrSubdomain.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class InitializeTenancyByDomainOrSubdomain
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
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'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue