mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 18:44:04 +00:00
Handle unnamed routes
If an unnamed route is passed to url()->toRoute(), the generated URL will receive the tenant parameter as long as the bypass parameter wasn't passed. Also remove the bypass parameter from the generated URL.
This commit is contained in:
parent
dc2be5b59f
commit
bff74c8c31
2 changed files with 31 additions and 8 deletions
|
|
@ -423,3 +423,25 @@ test('the toRoute method can automatically prefix the passed route name', functi
|
|||
// Passing the bypass parameter skips the name prefixing, so the method returns the central route URL
|
||||
expect(url()->toRoute($centralRoute, ['central' => true], true))->toBe('http://localhost/central/home');
|
||||
});
|
||||
|
||||
test('toRoute modifies parameters even when the route has no name', function () {
|
||||
config(['tenancy.bootstrappers' => [UrlGeneratorBootstrapper::class]]);
|
||||
|
||||
TenancyUrlGenerator::$passTenantParameterToRoutes = true;
|
||||
|
||||
$unnamedRoute = Route::get('/unnamed', fn () => 'unnamed');
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
// The tenant parameter is added to the URL even for unnamed routes
|
||||
expect(url()->toRoute($unnamedRoute, [], true))
|
||||
->toBe("http://localhost/unnamed?tenant={$tenant->getTenantKey()}");
|
||||
|
||||
// The bypass parameter prevents passing the tenant parameter and is stripped from the URL
|
||||
expect(url()->toRoute($unnamedRoute, ['central' => true], true))
|
||||
->toBe("http://localhost/unnamed")
|
||||
->not()->toContain('tenant=')
|
||||
->not()->toContain('central=');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue