mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 11:34:02 +00:00
Changed to Illuminate request instead of helper
This commit is contained in:
parent
432dd8fd1d
commit
b8d2c0f4db
1 changed files with 11 additions and 10 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Middleware;
|
namespace Stancl\Tenancy\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
||||||
|
|
||||||
class InitializeTenancyByRequestData
|
class InitializeTenancyByRequestData
|
||||||
|
|
@ -28,9 +29,9 @@ class InitializeTenancyByRequestData
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
if (request()->method() !== 'OPTIONS') {
|
if ($request->method() !== 'OPTIONS') {
|
||||||
try {
|
try {
|
||||||
$this->parseTenant();
|
$this->parseTenant($request);
|
||||||
} catch (TenantCouldNotBeIdentifiedException $e) {
|
} catch (TenantCouldNotBeIdentifiedException $e) {
|
||||||
($this->onFail)($e);
|
($this->onFail)($e);
|
||||||
}
|
}
|
||||||
|
|
@ -39,23 +40,23 @@ class InitializeTenancyByRequestData
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseTenant()
|
protected function parseTenant(Request $request)
|
||||||
{
|
{
|
||||||
if (tenancy()->initialized) {
|
if (tenancy()->initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tenant = null;
|
$tenant = null;
|
||||||
if (request()->hasHeader('X-Tenant')) {
|
if ($request->hasHeader('X-Tenant')) {
|
||||||
$tenant = request()->header('X-Tenant');
|
$tenant = $request->header('X-Tenant');
|
||||||
} elseif (request()->has('_tenant')) {
|
} elseif ($request->has('_tenant')) {
|
||||||
$tenant = request()->get('_tenant');
|
$tenant = $request->get('_tenant');
|
||||||
} elseif (! in_array(request()->getHost(), config('tenancy.exempt_domains', []), true)) {
|
} elseif (! in_array($request->getHost(), config('tenancy.exempt_domains', []), true)) {
|
||||||
$tenant = explode('.', request()->getHost())[0];
|
$tenant = explode('.', $request->getHost())[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $tenant) {
|
if (! $tenant) {
|
||||||
throw new TenantCouldNotBeIdentifiedException(request()->getHost());
|
throw new TenantCouldNotBeIdentifiedException($request->getHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
tenancy()->initialize(tenancy()->find($tenant));
|
tenancy()->initialize(tenancy()->find($tenant));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue