mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 18:24:03 +00:00
Merge pull request #4 from drbyte/patch-1
Update tenant-routes.blade.md
This commit is contained in:
commit
5df0dac047
1 changed files with 7 additions and 5 deletions
|
|
@ -7,7 +7,9 @@ section: content
|
||||||
|
|
||||||
# Tenant Routes {#tenant-routes}
|
# Tenant Routes {#tenant-routes}
|
||||||
|
|
||||||
Routes within `routes/tenant.php` will have the `web` middleware group and the `IntializeTenancy` middleware automatically applied on them. This middleware attempts to identify the tenant based on the current hostname. Once the tenant is identified, the database connection, cache, filesystem root paths and, optionally, Redis connection, will be switched.
|
Routes within `routes/tenant.php` will have the `web` middleware group and the `IntializeTenancy` middleware automatically applied on them.
|
||||||
|
|
||||||
|
The `IntializeTenancy` middleware attempts to identify the tenant based on the current hostname. Once the tenant is identified, the database connection, cache, filesystem root paths and, optionally, Redis connection, will be switched.
|
||||||
|
|
||||||
Just like `routes/web.php`, these routes use the `App\Http\Controllers` namespace (you can [configure this]({{ $page->link('configuration#tenant-route-namespace') }}))
|
Just like `routes/web.php`, these routes use the `App\Http\Controllers` namespace (you can [configure this]({{ $page->link('configuration#tenant-route-namespace') }}))
|
||||||
|
|
||||||
|
|
@ -17,7 +19,7 @@ Just like `routes/web.php`, these routes use the `App\Http\Controllers` namespac
|
||||||
|
|
||||||
Routes outside the `routes/tenant.php` file will not have the tenancy middleware automatically applied on them. You can apply this middleware manually, though.
|
Routes outside the `routes/tenant.php` file will not have the tenancy middleware automatically applied on them. You can apply this middleware manually, though.
|
||||||
|
|
||||||
If you want some of your, say, API routes to be multi-tenant, wrap them in a Route group with this middleware:
|
If you want certain routes (perhaps API routes) to be multi-tenant, wrap them in a Route group with this middleware:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Stancl\Tenancy\Middleware\InitializeTenancy;
|
use Stancl\Tenancy\Middleware\InitializeTenancy;
|
||||||
|
|
@ -44,8 +46,8 @@ protected $middlewareGroups = [
|
||||||
|
|
||||||
**You cannot have conflicting routes in `web.php` and `tenant.php`**. It would break `php artisan route:list` and route caching.
|
**You cannot have conflicting routes in `web.php` and `tenant.php`**. It would break `php artisan route:list` and route caching.
|
||||||
|
|
||||||
Since you probably want cleaner URLs on your non-tenant part of the application (landing page, etc), prefix your tenant routes with something like `/app`.
|
Suggestion: Since you probably want cleaner URLs on your non-tenant part of the application (landing page, etc), prefix your tenant routes with something like `/app`.
|
||||||
|
|
||||||
The `Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains` middleware prevents access to non-tenant routes from tenant domains by returning a redirect to the tenant app's home page ([`tenancy.home_url']({{ $page->link('configuration#home-url') }})). Conversely, it returns a 404 when a user attempts to visit a tenant route on a web (exempt) domain.
|
The `Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains` middleware prevents access to non-tenant routes from tenant domains by returning a redirect to the tenant app's home page ([`tenancy.home_url`]({{ $page->link('configuration#home-url') }})). Conversely, it returns a 404 when a user attempts to visit a tenant route on a web (exempt) domain.
|
||||||
|
|
||||||
The install command applies this middleware to the `web` group. If you want apply it for another route group, add this middleware manually to that group. You can do this in `app/Http/Kernel.php`.
|
The `tenancy:install` command applies this middleware to the `web` group. If you want apply it for another route group, add this middleware manually to that group. You can do this in `app/Http/Kernel.php`.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue