Tenants
This package offers support for multitenancy. It allows users to belong to multiple tenants and supports two tenant detection methods:
- detect tenant by subdomain
- detect tenant by session
Dependencies
This packages makes use of the following dependencies:
Domain model
Tenant detection methods
This packages offers two tenant detection methods.
Tenant detection by subdoman
This method determines the current tenant by comparing the domain of the current request with the value stored
in the domain column of the tenants table. When using this method the application must always be called by
the tenants subdomain (mytenant.myapp.tld). This method has a major advantage over detecting a tenant by session:
it allows determing the current tenant before the user logs in. This is required if you wan’t to display an tenant
based background image on te login page in example.
To use this method set the option tenant_finder in config/multitenanty.php to
\Spatie\Multitenancy\TenantFinder\DomainTenantFinder::class.
Also set the environment variable SESSION_DOMAIN of your .env to <domain>.<tld> (i.e.5up.de).
This setting make your session cookie available to all subdomains of <domain>.<tld>.
Now when creating a new tenant make shure to store the full domain of the tenant inside the domain column
of the tenants table (mytenant.myapp.tld).
Tenant detection by Session
This method determines the current tenant by checking the active_tenant_id attribute of the current session.
To detect the current tenant a user must be authenticated. When using this method, the application must always be
called by it’s main domain (myapp.tld).
To use this method set the option tenant_finder in config/multitenanty.php to
\JohnIt\Bc\Core\Domain\TenantFinders\SessionTenantFinder::class.