mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
Make universal routes work for controller middleware (#1151)
* Make universal routes work for controller middleware * add a fallback --------- Co-authored-by: chillbram <7299762+chillbram@users.noreply.github.com> Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
d268a06f5d
commit
5fe8825f13
2 changed files with 43 additions and 1 deletions
|
|
@ -63,4 +63,46 @@ class UniversalRouteTest extends TestCase
|
|||
->assertSuccessful()
|
||||
->assertSee('acme');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function universal_route_works_when_middleware_is_inserted_via_controller_middleware()
|
||||
{
|
||||
Route::middlewareGroup('universal', []);
|
||||
config(['tenancy.features' => [UniversalRoutes::class]]);
|
||||
|
||||
Route::get('/foo', [UniversalRouteController::class, 'show']);
|
||||
|
||||
$this->get('http://localhost/foo')
|
||||
->assertSuccessful()
|
||||
->assertSee('Tenancy is not initialized.');
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'acme.localhost',
|
||||
]);
|
||||
|
||||
$this->get('http://acme.localhost/foo')
|
||||
->assertSuccessful()
|
||||
->assertSee('Tenancy is initialized.');
|
||||
}
|
||||
}
|
||||
|
||||
class UniversalRouteController
|
||||
{
|
||||
public function getMiddleware()
|
||||
{
|
||||
return array_map(fn($middleware) => [
|
||||
'middleware' => $middleware,
|
||||
'options' => [],
|
||||
], ['universal', InitializeTenancyByDomain::class]);
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
return tenancy()->initialized
|
||||
? 'Tenancy is initialized.'
|
||||
: 'Tenancy is not initialized.';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue