mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 07:34:03 +00:00
Pass tenant parameter using defaults in UrlGeneratorBootstrapper, update tests accordingly (wip)
This commit is contained in:
parent
25360f6b6a
commit
83529316c3
3 changed files with 28 additions and 19 deletions
|
|
@ -10,6 +10,7 @@ use Illuminate\Support\Facades\URL;
|
|||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Overrides\TenancyUrlGenerator;
|
||||
use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||
|
||||
/**
|
||||
* Makes the app use TenancyUrlGenerator (instead of Illuminate\Routing\UrlGenerator) which:
|
||||
|
|
@ -32,7 +33,7 @@ class UrlGeneratorBootstrapper implements TenancyBootstrapper
|
|||
{
|
||||
URL::clearResolvedInstances();
|
||||
|
||||
$this->useTenancyUrlGenerator();
|
||||
$this->useTenancyUrlGenerator($tenant);
|
||||
}
|
||||
|
||||
public function revert(): void
|
||||
|
|
@ -45,7 +46,7 @@ class UrlGeneratorBootstrapper implements TenancyBootstrapper
|
|||
*
|
||||
* @see \Illuminate\Routing\RoutingServiceProvider registerUrlGenerator()
|
||||
*/
|
||||
protected function useTenancyUrlGenerator(): void
|
||||
protected function useTenancyUrlGenerator(Tenant $tenant): void
|
||||
{
|
||||
$newGenerator = new TenancyUrlGenerator(
|
||||
$this->app['router']->getRoutes(),
|
||||
|
|
@ -53,7 +54,12 @@ class UrlGeneratorBootstrapper implements TenancyBootstrapper
|
|||
$this->app['config']->get('app.asset_url'),
|
||||
);
|
||||
|
||||
$newGenerator->defaults($this->originalUrlGenerator->getDefaultParameters());
|
||||
$defaultParameters = array_merge(
|
||||
$this->originalUrlGenerator->getDefaultParameters(),
|
||||
[PathTenantResolver::tenantParameterName() => $tenant->getTenantKey()]
|
||||
);
|
||||
|
||||
$newGenerator->defaults($defaultParameters);
|
||||
|
||||
$newGenerator->setSessionResolver(function () {
|
||||
return $this->app['session'] ?? null;
|
||||
|
|
|
|||
|
|
@ -41,11 +41,10 @@ class TenancyUrlGenerator extends UrlGenerator
|
|||
/**
|
||||
* Determine if the tenant parameter should get passed
|
||||
* to the links generated by `route()` or `temporarySignedRoute()` whenever available
|
||||
* (enabled by default – works with both path and query string identification).
|
||||
*
|
||||
* With path identification, you can disable this and use URL::defaults() instead (as an alternative solution).
|
||||
* With path identification, you can keep this disabled since the parameter is passed automatically by URL::defaults() in the UrlGeneratorBootstrapper
|
||||
*/
|
||||
public static bool $passTenantParameterToRoutes = true;
|
||||
public static bool $passTenantParameterToRoutes = false;
|
||||
|
||||
/**
|
||||
* Override the route() method so that the route name gets prefixed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue