mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
[4.x] Set app.url config in UrlTenancyBootstrapper (#1068)
* Set `app.url` config in UrlTenancyBootstrapper * Add assertions * Set base app URL in config * Make UrlTenancyBootstrapper a singleton
This commit is contained in:
parent
617e9a7a73
commit
fbdb13f392
3 changed files with 20 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Bootstrappers;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
|
|
@ -16,6 +17,7 @@ class UrlTenancyBootstrapper implements TenancyBootstrapper
|
|||
|
||||
public function __construct(
|
||||
protected UrlGenerator $urlGenerator,
|
||||
protected Repository $config,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -24,12 +26,16 @@ class UrlTenancyBootstrapper implements TenancyBootstrapper
|
|||
$this->originalRootUrl = $this->urlGenerator->to('/');
|
||||
|
||||
if (static::$rootUrlOverride) {
|
||||
$this->urlGenerator->forceRootUrl((static::$rootUrlOverride)($tenant));
|
||||
$newRootUrl = (static::$rootUrlOverride)($tenant);
|
||||
|
||||
$this->urlGenerator->forceRootUrl($newRootUrl);
|
||||
$this->config->set('app.url', $newRootUrl);
|
||||
}
|
||||
}
|
||||
|
||||
public function revert(): void
|
||||
{
|
||||
$this->urlGenerator->forceRootUrl($this->originalRootUrl);
|
||||
$this->config->set('app.url', $this->originalRootUrl);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue