mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 23:14:05 +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 Illuminate\Support\Str;
|
||||||
use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||||
|
|
||||||
|
|
||||||
|
// todo@addTenantParameter revisit annotation
|
||||||
/**
|
/**
|
||||||
* Clones either all existing routes for which shouldBeCloned() returns true
|
* Clones either all existing routes for which shouldBeCloned() returns true
|
||||||
* (by default, all routes with any middleware present in $cloneRoutesWithMiddleware),
|
* (by default, all routes with any middleware present in $cloneRoutesWithMiddleware),
|
||||||
|
|
@ -70,6 +72,7 @@ use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||||
class CloneRoutesAsTenant
|
class CloneRoutesAsTenant
|
||||||
{
|
{
|
||||||
protected array $routesToClone = [];
|
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 $cloneUsing = null; // The callback should accept Route instance or the route name (string)
|
||||||
protected Closure|null $shouldClone = null;
|
protected Closure|null $shouldClone = null;
|
||||||
protected array $cloneRoutesWithMiddleware = ['clone'];
|
protected array $cloneRoutesWithMiddleware = ['clone'];
|
||||||
|
|
@ -111,6 +114,13 @@ class CloneRoutesAsTenant
|
||||||
$this->router->getRoutes()->refreshNameLookups();
|
$this->router->getRoutes()->refreshNameLookups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addTenantParameter(bool $addTenantParameter): static
|
||||||
|
{
|
||||||
|
$this->addTenantParameter = $addTenantParameter;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function cloneUsing(Closure|null $cloneUsing): static
|
public function cloneUsing(Closure|null $cloneUsing): static
|
||||||
{
|
{
|
||||||
$this->cloneUsing = $cloneUsing;
|
$this->cloneUsing = $cloneUsing;
|
||||||
|
|
@ -171,9 +181,11 @@ class CloneRoutesAsTenant
|
||||||
$action->put('as', PathTenantResolver::tenantRouteNamePrefix() . $name);
|
$action->put('as', PathTenantResolver::tenantRouteNamePrefix() . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
$action
|
$action->put('middleware', $middleware);
|
||||||
->put('middleware', $middleware)
|
|
||||||
->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}');
|
if ($this->addTenantParameter) {
|
||||||
|
$action->put('prefix', $prefix . '/{' . PathTenantResolver::tenantParameterName() . '}');
|
||||||
|
}
|
||||||
|
|
||||||
/** @var Route $newRoute */
|
/** @var Route $newRoute */
|
||||||
$newRoute = $this->router->$method($uri, $action->toArray());
|
$newRoute = $this->router->$method($uri, $action->toArray());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue