mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:14:04 +00:00
[1.8.0] Tenant redirect (#103)
This commit is contained in:
parent
6cee5d36ad
commit
b12b9c3a54
3 changed files with 40 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ use Stancl\Tenancy\Commands\Seed;
|
|||
use Illuminate\Cache\CacheManager;
|
||||
use Stancl\Tenancy\Commands\Install;
|
||||
use Stancl\Tenancy\Commands\Migrate;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Stancl\Tenancy\Commands\Rollback;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
|
@ -47,6 +48,21 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
]);
|
||||
|
||||
$this->app->register(TenantRouteServiceProvider::class);
|
||||
|
||||
$this->registerTenantRedirectMacro();
|
||||
}
|
||||
|
||||
public function registerTenantRedirectMacro()
|
||||
{
|
||||
RedirectResponse::macro('tenant', function (string $domain) {
|
||||
// replace first occurance of hostname fragment with $domain
|
||||
$url = $this->getTargetUrl();
|
||||
$hostname = \parse_url($url, PHP_URL_HOST);
|
||||
$position = \strpos($url, $hostname);
|
||||
$this->setTargetUrl(\substr_replace($url, $domain, $position, \strlen($hostname)));
|
||||
|
||||
return $this;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue