mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 20:54:03 +00:00
Add cookie option on Initialize Tenancy by Request identification
This commit is contained in:
parent
42dab2985a
commit
9eab5216b9
2 changed files with 23 additions and 10 deletions
|
|
@ -33,13 +33,18 @@ class InitializeTenancyByRequestData extends IdentificationMiddleware
|
||||||
|
|
||||||
protected function getPayload(Request $request): ?string
|
protected function getPayload(Request $request): ?string
|
||||||
{
|
{
|
||||||
$tenant = null;
|
|
||||||
if (static::$header && $request->hasHeader(static::$header)) {
|
if (static::$header && $request->hasHeader(static::$header)) {
|
||||||
$tenant = $request->header(static::$header);
|
return $request->header(static::$header);
|
||||||
} elseif (static::$queryParameter && $request->has(static::$queryParameter)) {
|
|
||||||
$tenant = $request->get(static::$queryParameter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tenant;
|
if (static::$queryParameter && $request->has(static::$queryParameter)) {
|
||||||
|
return $request->get(static::$queryParameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (static::$header && $request->hasCookie(static::$header)) {
|
||||||
|
return $request->cookie(static::$header);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,11 @@ afterEach(function () {
|
||||||
test('header identification works', function () {
|
test('header identification works', function () {
|
||||||
InitializeTenancyByRequestData::$header = 'X-Tenant';
|
InitializeTenancyByRequestData::$header = 'X-Tenant';
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
$tenant2 = Tenant::create();
|
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->withoutExceptionHandling()
|
->withoutExceptionHandling()
|
||||||
->get('test', [
|
->withHeader('X-Tenant', $tenant->id)
|
||||||
'X-Tenant' => $tenant->id,
|
->get('test')
|
||||||
])
|
|
||||||
->assertSee($tenant->id);
|
->assertSee($tenant->id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -40,10 +38,20 @@ test('query parameter identification works', function () {
|
||||||
InitializeTenancyByRequestData::$queryParameter = 'tenant';
|
InitializeTenancyByRequestData::$queryParameter = 'tenant';
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
$tenant2 = Tenant::create();
|
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->withoutExceptionHandling()
|
->withoutExceptionHandling()
|
||||||
->get('test?tenant=' . $tenant->id)
|
->get('test?tenant=' . $tenant->id)
|
||||||
->assertSee($tenant->id);
|
->assertSee($tenant->id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('cookie identification works', function () {
|
||||||
|
InitializeTenancyByRequestData::$header = 'X-Tenant';
|
||||||
|
$tenant = Tenant::create();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->withoutExceptionHandling()
|
||||||
|
->withUnencryptedCookie('X-Tenant', $tenant->id)
|
||||||
|
->get('test',)
|
||||||
|
->assertSee($tenant->id);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue