1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 23:04:03 +00:00

add cookie property

This commit is contained in:
Abrar Ahmad 2022-10-18 16:42:15 +05:00
parent 9eab5216b9
commit 0d7c52634a
2 changed files with 5 additions and 3 deletions

View file

@ -12,6 +12,7 @@ use Stancl\Tenancy\Tenancy;
class InitializeTenancyByRequestData extends IdentificationMiddleware class InitializeTenancyByRequestData extends IdentificationMiddleware
{ {
public static string $header = 'X-Tenant'; public static string $header = 'X-Tenant';
public static string $cookie = 'X-Tenant';
public static string $queryParameter = 'tenant'; public static string $queryParameter = 'tenant';
public static ?Closure $onFail = null; public static ?Closure $onFail = null;
@ -41,8 +42,8 @@ class InitializeTenancyByRequestData extends IdentificationMiddleware
return $request->get(static::$queryParameter); return $request->get(static::$queryParameter);
} }
if (static::$header && $request->hasCookie(static::$header)) { if (static::$cookie && $request->hasCookie(static::$cookie)) {
return $request->cookie(static::$header); return $request->cookie(static::$cookie);
} }
return null; return null;

View file

@ -20,6 +20,7 @@ beforeEach(function () {
afterEach(function () { afterEach(function () {
InitializeTenancyByRequestData::$header = 'X-Tenant'; InitializeTenancyByRequestData::$header = 'X-Tenant';
InitializeTenancyByRequestData::$cookie = 'X-Tenant';
InitializeTenancyByRequestData::$queryParameter = 'tenant'; InitializeTenancyByRequestData::$queryParameter = 'tenant';
}); });
@ -46,7 +47,7 @@ test('query parameter identification works', function () {
}); });
test('cookie identification works', function () { test('cookie identification works', function () {
InitializeTenancyByRequestData::$header = 'X-Tenant'; InitializeTenancyByRequestData::$cookie = 'X-Tenant';
$tenant = Tenant::create(); $tenant = Tenant::create();
$this $this