mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 08:24:05 +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;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
||||
|
||||
class InitializeTenancyByRequestData
|
||||
|
|
@ -28,9 +29,9 @@ class InitializeTenancyByRequestData
|
|||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (request()->method() !== 'OPTIONS') {
|
||||
if ($request->method() !== 'OPTIONS') {
|
||||
try {
|
||||
$this->parseTenant();
|
||||
$this->parseTenant($request);
|
||||
} catch (TenantCouldNotBeIdentifiedException $e) {
|
||||
($this->onFail)($e);
|
||||
}
|
||||
|
|
@ -39,23 +40,23 @@ class InitializeTenancyByRequestData
|
|||
return $next($request);
|
||||
}
|
||||
|
||||
protected function parseTenant()
|
||||
protected function parseTenant(Request $request)
|
||||
{
|
||||
if (tenancy()->initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tenant = null;
|
||||
if (request()->hasHeader('X-Tenant')) {
|
||||
$tenant = request()->header('X-Tenant');
|
||||
} elseif (request()->has('_tenant')) {
|
||||
$tenant = request()->get('_tenant');
|
||||
} elseif (! in_array(request()->getHost(), config('tenancy.exempt_domains', []), true)) {
|
||||
$tenant = explode('.', request()->getHost())[0];
|
||||
if ($request->hasHeader('X-Tenant')) {
|
||||
$tenant = $request->header('X-Tenant');
|
||||
} elseif ($request->has('_tenant')) {
|
||||
$tenant = $request->get('_tenant');
|
||||
} elseif (! in_array($request->getHost(), config('tenancy.exempt_domains', []), true)) {
|
||||
$tenant = explode('.', $request->getHost())[0];
|
||||
}
|
||||
|
||||
if (! $tenant) {
|
||||
throw new TenantCouldNotBeIdentifiedException(request()->getHost());
|
||||
throw new TenantCouldNotBeIdentifiedException($request->getHost());
|
||||
}
|
||||
|
||||
tenancy()->initialize(tenancy()->find($tenant));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue