From 4a4d76f8d18117915b4af88d8931067fbc0050e2 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 7 Jul 2025 11:46:46 +0200 Subject: [PATCH] Add $addTenantParameter properyt to the clone action --- src/Actions/CloneRoutesAsTenant.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Actions/CloneRoutesAsTenant.php b/src/Actions/CloneRoutesAsTenant.php index c5818878..15cd1167 100644 --- a/src/Actions/CloneRoutesAsTenant.php +++ b/src/Actions/CloneRoutesAsTenant.php @@ -10,6 +10,8 @@ use Illuminate\Routing\Router; use Illuminate\Support\Str; use Stancl\Tenancy\Resolvers\PathTenantResolver; + +// todo@addTenantParameter revisit annotation /** * Clones either all existing routes for which shouldBeCloned() returns true * (by default, all routes with any middleware present in $cloneRoutesWithMiddleware), @@ -70,6 +72,7 @@ use Stancl\Tenancy\Resolvers\PathTenantResolver; class CloneRoutesAsTenant { protected array $routesToClone = []; + protected bool $addTenantParameter = true; protected Closure|null $cloneUsing = null; // The callback should accept Route instance or the route name (string) protected Closure|null $shouldClone = null; protected array $cloneRoutesWithMiddleware = ['clone']; @@ -111,6 +114,13 @@ class CloneRoutesAsTenant $this->router->getRoutes()->refreshNameLookups(); } + public function addTenantParameter(bool $addTenantParameter): static + { + $this->addTenantParameter = $addTenantParameter; + + return $this; + } + public function cloneUsing(Closure|null $cloneUsing): static { $this->cloneUsing = $cloneUsing; @@ -171,9 +181,11 @@ class CloneRoutesAsTenant $action->put('as', PathTenantResolver::tenantRouteNamePrefix() . $name); } - $action - ->put('middleware', $middleware) - ->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}'); + $action->put('middleware', $middleware); + + if ($this->addTenantParameter) { + $action->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}'); + } /** @var Route $newRoute */ $newRoute = $this->router->$method($uri, $action->toArray());