mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 13:54:03 +00:00
Cloning: clarify case where neither paths nor domains differ
In such a case, the cloned route will actually *override* the original route, rather than being unused as the original docblock claimed. Also adds a static make() function for convenience.
This commit is contained in:
parent
69bf768424
commit
97c5afd2cf
2 changed files with 21 additions and 1 deletions
|
|
@ -71,7 +71,7 @@ use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||||
* // cloned route can be customized using domain(string|null). By default, the cloned route will not be scoped to a domain,
|
* // cloned route can be customized using domain(string|null). By default, the cloned route will not be scoped to a domain,
|
||||||
* // unless a domain() call is used. It's important to keep in mind that:
|
* // unless a domain() call is used. It's important to keep in mind that:
|
||||||
* // 1. When addTenantParameter(false) is used, the paths will be the same, thus domains must differ.
|
* // 1. When addTenantParameter(false) is used, the paths will be the same, thus domains must differ.
|
||||||
* // 2. If the original route (with the same path) has no domain, the cloned route will never be used due to registration order.
|
* // 2. If the original route has no domain, the cloned route will override the original route as they will directly conflict.
|
||||||
* $cloneAction->addTenantParameter(false)->cloneRoutesWithMiddleware(['clone'])->cloneRoute('no-tenant-parameter')->handle();
|
* $cloneAction->addTenantParameter(false)->cloneRoutesWithMiddleware(['clone'])->cloneRoute('no-tenant-parameter')->handle();
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
|
@ -96,6 +96,11 @@ class CloneRoutesAsTenant
|
||||||
protected Router $router,
|
protected Router $router,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
public static function make(): static
|
||||||
|
{
|
||||||
|
return app(static::class);
|
||||||
|
}
|
||||||
|
|
||||||
/** Clone routes. This resets routesToClone() but not other config. */
|
/** Clone routes. This resets routesToClone() but not other config. */
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -422,3 +422,18 @@ test('existing context flags are removed during cloning', function () {
|
||||||
expect(tenancy()->getRouteMiddleware(RouteFacade::getRoutes()->getByName('tenant.foo')))
|
expect(tenancy()->getRouteMiddleware(RouteFacade::getRoutes()->getByName('tenant.foo')))
|
||||||
->not()->toContain('universal');
|
->not()->toContain('universal');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('cloning a route without a prefix or differing domains overrides the original route', function () {
|
||||||
|
RouteFacade::get('/foo', fn () => true)->name('foo')->middleware(['clone']);
|
||||||
|
|
||||||
|
expect(collect(RouteFacade::getRoutes()->get())->map->getName())->toContain('foo');
|
||||||
|
|
||||||
|
$cloneAction = CloneRoutesAsTenant::make();
|
||||||
|
$cloneAction->cloneRoute('foo')
|
||||||
|
->addTenantParameter(false)
|
||||||
|
->tenantParameterBeforePrefix(false)
|
||||||
|
->handle();
|
||||||
|
|
||||||
|
expect(collect(RouteFacade::getRoutes()->get())->map->getName())->toContain('tenant.foo');
|
||||||
|
expect(collect(RouteFacade::getRoutes()->get())->map->getName())->not()->toContain('foo');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue