1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:54:05 +00:00

Add tenant parameter BEFORE existing prefixes by default, add tenantParameterBeforePrefix() to allow customizing this (#1393)

This commit is contained in:
lukinovec 2025-09-03 15:56:12 +02:00 committed by GitHub
parent 364637dc23
commit d983bf9547
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 13 deletions

View file

@ -86,6 +86,7 @@ class CloneRoutesAsTenant
{
protected array $routesToClone = [];
protected bool $addTenantParameter = true;
protected bool $tenantParameterBeforePrefix = true;
protected string|null $domain = null;
protected Closure|null $cloneUsing = null; // The callback should accept Route instance or the route name (string)
protected Closure|null $shouldClone = null;
@ -177,6 +178,13 @@ class CloneRoutesAsTenant
return $this;
}
public function tenantParameterBeforePrefix(bool $tenantParameterBeforePrefix): static
{
$this->tenantParameterBeforePrefix = $tenantParameterBeforePrefix;
return $this;
}
/** Clone an individual route. */
public function cloneRoute(Route|string $route): static
{
@ -226,7 +234,13 @@ class CloneRoutesAsTenant
$action->put('middleware', $middleware);
if ($this->addTenantParameter) {
$action->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}');
$tenantParameter = '{' . PathTenantResolver::tenantParameterName() . '}';
$newPrefix = $this->tenantParameterBeforePrefix
? $tenantParameter . '/' . $prefix
: $prefix . '/' . $tenantParameter;
$action->put('prefix', $newPrefix);
}
/** @var Route $newRoute */