Multi tenancy package for laravel applications (multi-database)
Install this package with composer:
composer require dartika/laravel-mtenancy
Add this provider to your config/app.php:
'providers' => [
// ...
Dartika\MultiTenancy\TenantServiceProvider::class,
]
To bind the public assets url to public tenant's files, use this in your nginx vhost:
server_name ~^(?<subdomain>\w+)\.yourdomain.com;
location /files/ {
rewrite ^(.*?)$ /../storage/app/tenants/$subdomain/public/$1 break;
}
$ php artisan tenant:list
# List all tenants
$ php artisan tenant:create tenant_name
# Create tenant
$ php artisan tenant:delete tenant_name
# Delete tenant
$ php artisan tenant:migrate [tenant_name] [--secure]
# Migrate tenant/s (and backup tenant if --secure flag is enabled and there is a migrations)
$ php artisan tenant:backup [tenant_name]
# Backup tenant (to tenant/backups path)
$ php artisan tenant:backup-clean [tenant_name] [--days=15]
# Clean tenant backups keeping the latest "--days" backups
$ php artisan tenant:tinker [tenant_name]
# Open tinker with tenant activated. (NOTE: Tinker must be available in project)