From c0c47c54704126590a901b182448bb4942e2e3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sun, 14 Apr 2024 00:02:57 +0200 Subject: [PATCH] update docs for laravel 11 --- .../v3/features/universal-routes.blade.md | 6 +- source/docs/v3/installation.blade.md | 19 ++---- source/docs/v3/quickstart.blade.md | 60 ++++--------------- 3 files changed, 23 insertions(+), 62 deletions(-) diff --git a/source/docs/v3/features/universal-routes.blade.md b/source/docs/v3/features/universal-routes.blade.md index 8169d3f..db5d5bb 100644 --- a/source/docs/v3/features/universal-routes.blade.md +++ b/source/docs/v3/features/universal-routes.blade.md @@ -18,10 +18,12 @@ First, enable the `UniversalRoutes` feature by uncommenting the following line i Stancl\Tenancy\Features\UniversalRoutes::class, ``` -Next, go to your `app/Http/Kernel.php` file and add the following middleware group: +Next, go to your `bootstrap/app.php` file and add the following middleware group: ```php -'universal' => [], +->withMiddleware(function (Middleware $middleware) { + $middleware->group('universal', []); +}) ``` We will use this middleware group as a "flag" on the route, to mark it as a universal route. We don't need any actual middleware inside the group. diff --git a/source/docs/v3/installation.blade.md b/source/docs/v3/installation.blade.md index 81e1777..7520727 100644 --- a/source/docs/v3/installation.blade.md +++ b/source/docs/v3/installation.blade.md @@ -6,9 +6,7 @@ section: content # Installation {#installation} -> Note: Laravel 11 has a different folder structure than Laravel 10. An updated installation guide is coming soon. For now you can see [this discussion](https://github.com/archtechx/tenancy/pull/1180). - -Laravel 6.0 or higher is needed. +Laravel 9.0 or higher is needed. Require the package using composer: @@ -29,18 +27,13 @@ It will create: - a routes file (`routes/tenant.php`), - and a service provider file `app/Providers/TenancyServiceProvider.php` -Then add the service provider to your `config/app.php` file: +Then add the service provider to your `bootstrap/providers.php` file: ```php -/* - * Application Service Providers... - */ -App\Providers\AppServiceProvider::class, -App\Providers\AuthServiceProvider::class, -// App\Providers\BroadcastServiceProvider::class, -App\Providers\EventServiceProvider::class, -App\Providers\RouteServiceProvider::class, -App\Providers\TenancyServiceProvider::class, // <-- here +return [ + App\Providers\AppServiceProvider::class, + App\Providers\TenancyServiceProvider::class, // <-- here +]; ``` And finally, if you want to use a different central database than the one defined by `DB_CONNECTION` in the file `.env`, name your central connection (in `config/database.php`) `central` — or however else you want, but make sure it's the same name as the `tenancy.central_connection` config. diff --git a/source/docs/v3/quickstart.blade.md b/source/docs/v3/quickstart.blade.md index 7ea8c06..2d4840e 100644 --- a/source/docs/v3/quickstart.blade.md +++ b/source/docs/v3/quickstart.blade.md @@ -34,18 +34,13 @@ Let's run the migrations: php artisan migrate ``` -Register the service provider in `config/app.php`. Make sure it's on the same position as in the code snippet below: +Register the service provider in `bootstrap/providers.php`: ```php -/* - * Application Service Providers... - */ -App\Providers\AppServiceProvider::class, -App\Providers\AuthServiceProvider::class, -// App\Providers\BroadcastServiceProvider::class, -App\Providers\EventServiceProvider::class, -App\Providers\RouteServiceProvider::class, -App\Providers\TenancyServiceProvider::class, // <-- here +return [ + App\Providers\AppServiceProvider::class, + App\Providers\TenancyServiceProvider::class, // <-- here +]; ``` ## Creating a tenant model {#creating-a-tenant-model} @@ -84,50 +79,20 @@ In other words, it creates & migrates the tenant's database after he's created ## Central routes {#central-routes} -We'll make a small change to the `app/Providers/RouteServiceProvider.php` file. Specifically, we'll make sure that central routes are registered on central domains only. +We'll make a small change to your existing route files. Specifically, we'll make sure that central routes are registered on central domains only: ```php -protected function mapWebRoutes() -{ - foreach ($this->centralDomains() as $domain) { - Route::middleware('web') - ->domain($domain) - ->namespace($this->namespace) - ->group(base_path('routes/web.php')); - } -} +// routes/web.php, api.php or any other central route files you have -protected function mapApiRoutes() -{ - foreach ($this->centralDomains() as $domain) { - Route::prefix('api') - ->domain($domain) - ->middleware('api') - ->namespace($this->namespace) - ->group(base_path('routes/api.php')); - } -} - -protected function centralDomains(): array -{ - return config('tenancy.central_domains'); -} -``` - -Call these methods manually from your `RouteServiceProvider`'s `boot()` method, instead of the `$this->routes()` calls. - -```php -public function boot() -{ - $this->configureRateLimiting(); - - $this->routes(function () { - $this->mapApiRoutes(); - $this->mapWebRoutes(); +foreach (config('tenancy.central_domains') as $domain) { + Route::domain($domain)->group(function () { + // your actual routes }); } ``` +Alternatively, to keep your route files more clean, you can use [this approach](https://github.com/archtechx/tenancy/pull/1180#issuecomment-2006098346) to register all of your routes in the `using` callback of the Application Builder. + ## Central domains {#central-domains} Now we need to actually specify the central domains. A central domain is a domain that serves your "central app" content, e.g. the landing page where tenants sign up. Open the `config/tenancy.php` file and add them in: @@ -146,6 +111,7 @@ If you're using Laravel Sail, no changes are needed, default values are good to 'localhost', ], ``` + ## Tenant routes {#tenant-routes} Your tenant routes will look like this by default: