mirror of
https://github.com/archtechx/tenancy.git
synced 2026-03-22 03:34:04 +00:00
Add toRoute() override to TenancyUrlGenerator
Also update `route()` override since `parent::route()` calls `toRoute()` under the hood (similarly to how `parent::temporarySignedRoute()` calls `route()`)
This commit is contained in:
parent
8f3ea6297f
commit
883b91805a
2 changed files with 50 additions and 1 deletions
|
|
@ -401,3 +401,25 @@ test('the bypass parameter works correctly with temporarySignedRoute', function(
|
|||
->toContain('localhost/foo')
|
||||
->not()->toContain('central='); // Bypass parameter gets removed from the generated URL
|
||||
});
|
||||
|
||||
test('the toRoute method can automatically prefix the passed route name', function () {
|
||||
config(['tenancy.bootstrappers' => [UrlGeneratorBootstrapper::class]]);
|
||||
|
||||
Route::get('/central/home', fn () => 'central')->name('home');
|
||||
Route::get('/tenant/home', fn () => 'tenant')->name('tenant.home');
|
||||
|
||||
TenancyUrlGenerator::$prefixRouteNames = true;
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$centralRoute = Route::getRoutes()->getByName('home');
|
||||
|
||||
// url()->toRoute() prefixes the name of the passed route ('home') with the tenant prefix
|
||||
// and generates the URL for the tenant route (as if the 'tenant.home' route was passed to the method)
|
||||
expect(url()->toRoute($centralRoute, [], true))->toBe('http://localhost/tenant/home');
|
||||
|
||||
// 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');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue