mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:34:04 +00:00
Add $addTenantParameter properyt to the clone action
This commit is contained in:
parent
ca57b89d02
commit
4a4d76f8d1
1 changed files with 15 additions and 3 deletions
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue