Multi-Tenancy Last updated: 2024-11-22
Enabling Tenancy in Dash Starting from Version 1.1.60
Available On Laravel (v10) in Laravel 11 Soon
Dash now supports tenancy starting from version 1.1.60, integrated with the Tenancy for Laravel (v3) with Laravel (v10) library. Below are the detailed steps to activate and configure tenancy in Dash:
1. Install Tenancy for Laravel v3
Follow the installation and setup steps for Tenancy for Laravel from the official documentation: Tenancy for Laravel v3 Quickstart
2. Register Service Providers
Ensure that DashServiceProvider
is loaded before TenancyServiceProvider
in the config/app.php
file.
'providers' => [
App\Providers\AppServiceProvider::class,
App\Providers\DashServiceProvider::class, // Dash provider
App\Providers\TenancyServiceProvider::class, // Tenancy provider
],
3. Enable Tenancy Mode in Dash Configuration
Add this on your dash.php if you are using old version or Update the tenancy_mode
setting in config/dash.php
to on
as shown below:
'tenancy' => [
'tenancy_mode' => 'on', // Options: 'on' or 'off'
],
4. Add Middleware
Open the app/Http/Kernel.php
file, and in the $middleware
array, add the InitializeTenancyByDomain
middleware from Dash.
protected $middleware = [
// Other middlewares...
\Dash\Middleware\InitializeTenancyByDomain::class, // Add this middleware
];
5. Update tenancy.php
Configuration
a. Enable Features
Ensure the following features are activated in the features
array of the config/tenancy.php
file:
'features' => [
\Stancl\Tenancy\Features\UserImpersonation::class,
\Stancl\Tenancy\Features\UniversalRoutes::class,
],
b. Set Central Domains
Add central domains to the central_domains
array:
'central_domains' => [
env('TENANCY_DEFAULT_DOMAIN'), // Example: default domain from .env
// '127.0.0.1', 'localhost', or other domains
],
6. Migrations for Tenants
Move the migration files related to tenant-specific data into the tenant
folder. This ensures the tenant database structure is created correctly.
7. Define the Tenant Model
Create a Tenant
model in App\Models\Tenant
and configure it in tenancy.php
:
'tenant_model' => \App\Models\Tenant::class,
This step is detailed in the Tenancy for Laravel installation guide.
Final Notes
Ensure all configuration files, especially dash.php
and tenancy.php
, are properly set up to match your application's requirements. Refer to the Tenancy for Laravel Documentation for advanced configurations or troubleshooting.