Tenant Resolution
The documentation is still in progress, and this page is not yet complete. Please check back again in the future.
Introduction
Tenant resolution is the process of determining the current tenant, and then resolving it before setting it as the actual current tenant. Within Sprout, there are two paths for tenant resolution, identifying, and loading.
Identifying Tenants
Tenant identification is a process that uses the tenant identifier to identify the
tenant.
This is the automated process that makes sure that the correct tenant is available when processing your routes.
To achieve this, an identity resolver is used, which is a class that is responsible for extracting a tenants'
identifier from an incoming HTTP request.
These resolvers are configured using the multitenancy.resolvers
configuration
option.
These classes also know how to configure a route to make the best use of themselves.
Tenant Routes
Your multitenanted application will have routes that require a current tenant, which is what we refer to as tenant routes, because they belong to the tenant. There are two ways to define tenant routes, but both allow you to set two optional parameters, which follow the same rules as middleware parameters.
- The resolver — The name of a resolver registered in the
multitenancy.resolvers
config. - The tenancy — The name of a tenancy registered in the
multitenancy.tenancies
config.
Automatic Routes
The best way to define tenant routes is using the router macro that's used in the installation guide. These routes are defined like this.
1// Default 2Route::tenanted(function () { 3 // Tenant Routes 4}); 5 6// Default tenancy, manual resolver 7Route::tenanted(function () { 8 // Tenant Routes 9}, 'subdomain');10 11// Default resolver, manual tenancy12Route::tenanted(function () {13 // Tenant Routes14}, null, 'tenants');15 16// Manual resolver, manual tenancy17Route::tenanted(function () {18 // Tenant Routes19}, 'subdomain', 'tenants');
Manual Routes
Sometimes you need to manually specify a route as being tenanted, and in those cases all you need is the sprout. tenanted
middleware, which is an alias for Sprout\Http\Middleware\SproutTenantContextMiddleware
.
You can provide the middleware like this.
1// Default 2Route::middleware(['sprout.tenanted'])->get('/', ''); 3 4// Default tenancy, manual resolver 5Route::middleware(['sprout.tenanted:subdomain'])->get('/', ''); 6 7// Default resolver, manual tenancy 8Route::middleware(['sprout.tenanted:,tenants'])->get('/', ''); 9 10// Manual resolver, manual tenancy11Route::middleware(['sprout.tenanted:subdomain,tenants'])->get('/', '');