Skip to content

Commit

Permalink
Update base-installation.md
Browse files Browse the repository at this point in the history
  • Loading branch information
masterix21 committed Jul 30, 2024
1 parent 4182c8d commit 913fbdf
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions docs/installation/base-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,36 @@ return [

To prevent users from a tenant abusing their session to access another tenant, you must use the `Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession` middleware on all tenant-aware routes.

If all your application routes are tenant-aware, you can add it to your global middleware in `app\Http\Kernel.php`
If all your application routes are tenant-aware, you can add it to your global middleware in `bootstrap/app.php`

```php
// in `app\Http\Kernel.php`
// in `bootstrap/app.php`

protected $middlewareGroups = [
'web' => [
// ...
\Spatie\Multitenancy\Http\Middleware\NeedsTenant::class,
\Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession::class,
]
];
return Application::configure(basePath: dirname(__DIR__))
// ...
->withMiddleware(function (Middleware $middleware) {
$middleware
->appendToGroup('web', [
\Spatie\Multitenancy\Http\Middleware\NeedsTenant::class,
\Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession::class,
]);
});
```

If only some routes are tenant-aware, create a new middleware group:

```php
// in `app\Http\Kernel.php`
// in `bootstrap/app.php`

protected $middlewareGroups = [
return Application::configure(basePath: dirname(__DIR__))
// ...
'tenant' => [
\Spatie\Multitenancy\Http\Middleware\NeedsTenant::class,
\Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession::class,
]
];
->withMiddleware(function (Middleware $middleware) {
$middleware
->group('tenant', [
\Spatie\Multitenancy\Http\Middleware\NeedsTenant::class,
\Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession::class,
]);
});
```

Then apply the group to the appropriate routes:
Expand Down

0 comments on commit 913fbdf

Please sign in to comment.