mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:34:04 +00:00
Trim trailing / from route prefixes during route cloning (#55)
* route cloning: Trim '/' from original route prefixes * Add test for the trimming of route prefixes * Revert "Add test for the trimming of route prefixes" This reverts commit 568ae17d2bf8d5542a0e46840f7604c6a0df236d. * Add test for the trimming of route prefixes * Delete extra comments [ci skip] * Fix regression test [ci skip] * trigger CI * Add routes with trailing slashes to the cloned route prefixing test * Test nested '/' route cloning * Update cloned route creation as suggested * fix terminology * add comment to test --------- Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
a9ab646e59
commit
0f7cd2e868
2 changed files with 73 additions and 18 deletions
|
|
@ -150,9 +150,10 @@ class CloneRoutesAsTenant
|
|||
protected function createNewRoute(Route $route): Route
|
||||
{
|
||||
$method = strtolower($route->methods()[0]);
|
||||
$uri = $route->getPrefix() ? Str::after($route->uri(), $route->getPrefix()) : $route->uri();
|
||||
$prefix = trim($route->getPrefix() ?? '', '/');
|
||||
$uri = $route->getPrefix() ? Str::after($route->uri(), $prefix) : $route->uri();
|
||||
|
||||
$newRouteAction = collect($route->action)->tap(function (Collection $action) use ($route) {
|
||||
$newRouteAction = collect($route->action)->tap(function (Collection $action) use ($route, $prefix) {
|
||||
/** @var array $routeMiddleware */
|
||||
$routeMiddleware = $action->get('middleware') ?? [];
|
||||
|
||||
|
|
@ -174,7 +175,7 @@ class CloneRoutesAsTenant
|
|||
return $action
|
||||
->put('as', $newRouteNamePrefix)
|
||||
->put('middleware', $newRouteMiddleware)
|
||||
->put('prefix', $route->getPrefix() . '/{' . PathTenantResolver::tenantParameterName() . '}');
|
||||
->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}');
|
||||
})->toArray();
|
||||
|
||||
/** @var Route $newRoute */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue