mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 09:54:05 +00:00
CloneRoutesAsTenant cleanup
This commit is contained in:
parent
1bade8eee7
commit
74e702105a
1 changed files with 5 additions and 10 deletions
|
|
@ -142,17 +142,13 @@ class CloneRoutesAsTenant
|
||||||
// Add the 'tenant' middleware to the new route
|
// Add the 'tenant' middleware to the new route
|
||||||
// Exclude $this->cloneRoutesWithMiddleware MW from the new route (it should only be flagged as tenant)
|
// Exclude $this->cloneRoutesWithMiddleware MW from the new route (it should only be flagged as tenant)
|
||||||
|
|
||||||
/** @var array $middleware */
|
$middleware = $this->processMiddlewareForCloning($action->get('middleware') ?? []);
|
||||||
$middleware = $action->get('middleware') ?? [];
|
|
||||||
$middleware = $this->processMiddlewareForCloning($middleware);
|
|
||||||
$name = $route->getName();
|
|
||||||
|
|
||||||
if ($name) {
|
if ($name = $route->getName()) {
|
||||||
$name = PathTenantResolver::tenantRouteNamePrefix() . $name;
|
$action->put('as', PathTenantResolver::tenantRouteNamePrefix() . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
$action
|
$action
|
||||||
->put('as', $name)
|
|
||||||
->put('middleware', $middleware)
|
->put('middleware', $middleware)
|
||||||
->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}');
|
->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}');
|
||||||
|
|
||||||
|
|
@ -177,11 +173,10 @@ class CloneRoutesAsTenant
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes top-level cloneRoutesWithMiddleware and adds 'tenant' middleware. */
|
/** Removes top-level cloneRoutesWithMiddleware and adds 'tenant' middleware. */
|
||||||
protected function processMiddlewareForCloning(array $middlewares): array
|
protected function processMiddlewareForCloning(array $middleware): array
|
||||||
{
|
{
|
||||||
// Filter out top-level cloneRoutesWithMiddleware and add the 'tenant' flag
|
|
||||||
$processedMiddleware = array_filter(
|
$processedMiddleware = array_filter(
|
||||||
$middlewares,
|
$middleware,
|
||||||
fn ($mw) => ! in_array($mw, $this->cloneRoutesWithMiddleware)
|
fn ($mw) => ! in_array($mw, $this->cloneRoutesWithMiddleware)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue