mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:14:03 +00:00
Load the middleware from the SP, fix #3
This commit is contained in:
parent
94aee1e485
commit
89d97a89ab
2 changed files with 9 additions and 17 deletions
21
README.md
21
README.md
|
|
@ -18,30 +18,17 @@ You won't have to change a thing in your application's code.
|
||||||
composer require stancl/tenancy
|
composer require stancl/tenancy
|
||||||
```
|
```
|
||||||
|
|
||||||
### Adding the `InitializeTenancy` middleware
|
### Configuring the `InitializeTenancy` middleware
|
||||||
|
|
||||||
Open `app/Http/Kernel.php` and make the following changes:
|
The `TenancyServiceProvider` automatically adds the `tenancy` middleware group which can be assigned to routes. You only need to make sure the middleware is top priority.
|
||||||
|
|
||||||
First, you want to create middleware groups so that we can apply this middleware on routes.
|
Open `app/Http/Kernel.php` and make the middleware top priority, so that it gets executed before anything else, making sure things like the database switch connections soon enough.
|
||||||
- Create a new middleware group in `$middlewareGroups`:
|
|
||||||
```php
|
|
||||||
'tenancy' => [
|
|
||||||
\Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
|
||||||
],
|
|
||||||
```
|
|
||||||
- Create a new middleware group in `$routeMiddleware`:
|
|
||||||
```php
|
|
||||||
'tenancy' => \Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
|
||||||
```
|
|
||||||
- Make the middleware top priority, so that it gets executed before anything else, thus making sure things like the database switch connections soon enough.
|
|
||||||
```php
|
```php
|
||||||
protected $middlewarePriority = [
|
protected $middlewarePriority = [
|
||||||
\Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
\Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Configuring the middleware
|
When a tenant route is visited, but the tenant can't be identified, an exception is thrown. If you want to change this behavior, to a redirect for example, add this to your `app/Providers/AppServiceProvider.php`'s `boot()` method.
|
||||||
|
|
||||||
When a tenant route is visited, but the tenant can't be identified, an exception can be thrown. If you want to change this behavior, to a redirect for example, add this to your `app/Providers/AppServiceProvider.php`'s `boot()` method.
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
// use Stancl\Tenancy\Middleware\InitializeTenancy;
|
// use Stancl\Tenancy\Middleware\InitializeTenancy;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use Stancl\Tenancy\TenantManager;
|
||||||
use Stancl\Tenancy\DatabaseManager;
|
use Stancl\Tenancy\DatabaseManager;
|
||||||
use Stancl\Tenancy\Commands\Migrate;
|
use Stancl\Tenancy\Commands\Migrate;
|
||||||
use Stancl\Tenancy\Commands\Rollback;
|
use Stancl\Tenancy\Commands\Rollback;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Stancl\Tenancy\Commands\TenantList;
|
use Stancl\Tenancy\Commands\TenantList;
|
||||||
use Stancl\Tenancy\Interfaces\StorageDriver;
|
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||||
|
|
@ -35,6 +36,10 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
], 'config');
|
], 'config');
|
||||||
|
|
||||||
$this->loadRoutesFrom(__DIR__ . '/routes.php');
|
$this->loadRoutesFrom(__DIR__ . '/routes.php');
|
||||||
|
|
||||||
|
Route::middlewareGroup('tenancy', [
|
||||||
|
\Stancl\Tenancy\Middleware\InitializeTenancy::class
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue