Skip to content

Laravel Fortify integration

Fortify redirects users to the URLs configured in its home and redirects config, e.g. after logging in. By default, the same URLs are used in both the central and the tenant context. The FortifyRouteBootstrapper lets you use tenant routes for these redirects in the tenant context.

To enable the bootstrapper, uncomment the FortifyRouteBootstrapper line in the bootstrappers section of the tenancy config:

config/tenancy.php
'bootstrappers' => [
// Bootstrappers\Integrations\FortifyRouteBootstrapper::class,
],

When tenancy is initialized, the bootstrapper generates URLs for the configured tenant routes and sets them in the fortify config. When tenancy is ended, the original fortify config is restored.

The bootstrapper is configured using static properties, typically in your TenancyServiceProvider:

app/Providers/TenancyServiceProvider.php
use Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteBootstrapper;
// Tenant route used as Fortify's home (fortify.home), 'tenant.dashboard' by default
FortifyRouteBootstrapper::$fortifyHome = 'tenant.dashboard';
// Fortify redirects (fortify.redirects) mapped to tenant route names
FortifyRouteBootstrapper::$fortifyRedirectMap = [
'login' => 'tenant.welcome',
];

Redirects that aren’t in $fortifyRedirectMap keep the values from your Fortify config. Setting $fortifyHome to null leaves fortify.home unchanged.

With domain identification, the generated URLs don’t need any tenant parameter — the routes are just generated on the current domain.

With path identification, you usually don’t need to pass the parameter either. If you use the UrlGeneratorBootstrapper, it adds the tenant parameter to the URL defaults, so the generated URLs include it automatically.

With query string identification, the tenant has to be passed to the routes. To do that, enable $passTenantParameter:

FortifyRouteBootstrapper::$passTenantParameter = true;

The parameter then follows the query_parameter config of the RequestDataTenantResolver.

If you do need to pass the parameter with path identification, enable $passTenantParameter and disable $passQueryParameter, so that the tenant_parameter_name config of the PathTenantResolver is used instead:

FortifyRouteBootstrapper::$passTenantParameter = true;
FortifyRouteBootstrapper::$passQueryParameter = false;