mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:34:03 +00:00
[4.x] Allow user to customize tenant's URL root in CLI (#1044)
* Add UrlTenancyBootstrapper * Fix code style (php-cs-fixer) * Move URL overriding to a separate method, call it in `boot()` * Test URL root overriding * Change parameter formatting Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> * Fix code style (php-cs-fixer) * Improve URL bootstrapper test * Move `$scheme` and `$hostname` to the closure * Update code example comment * Hardcode values instead of referencing variables * Delete extra line --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
parent
a006e49881
commit
617e9a7a73
4 changed files with 102 additions and 6 deletions
|
|
@ -4,14 +4,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use Stancl\Tenancy\Jobs;
|
||||
use Stancl\Tenancy\Events;
|
||||
use Stancl\Tenancy\Listeners;
|
||||
use Stancl\Tenancy\Middleware;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Events;
|
||||
use Stancl\Tenancy\Jobs;
|
||||
use Stancl\Tenancy\Listeners;
|
||||
use Stancl\Tenancy\Middleware;
|
||||
|
||||
class TenancyServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -118,6 +118,21 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
];
|
||||
}
|
||||
|
||||
protected function overrideUrlInTenantContext(): void
|
||||
{
|
||||
/**
|
||||
* Example of CLI tenant URL root override:
|
||||
*
|
||||
* UrlTenancyBootstrapper::$rootUrlOverride = function (Tenant $tenant) {
|
||||
* $baseUrl = url('/');
|
||||
* $scheme = str($baseUrl)->before('://');
|
||||
* $hostname = str($baseUrl)->after($scheme . '://');
|
||||
*
|
||||
* return $scheme . '://' . $tenant->getTenantKey() . '.' . $hostname;
|
||||
*};
|
||||
*/
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
|
|
@ -129,6 +144,7 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
$this->mapRoutes();
|
||||
|
||||
$this->makeTenancyMiddlewareHighestPriority();
|
||||
$this->overrideUrlInTenantContext();
|
||||
}
|
||||
|
||||
protected function bootEvents()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue