Install via composer
composer require joaovdiasb/laravel-multi-tenancy
- Publish provider and migrate:
php artisan vendor:publish --provider="Joaovdiasb\LaravelMultiTenancy\LaravelMultiTenancyServiceProvider" && php artisan migrate --path=./database/migrations/tenant
- Add env variable
TENANT_ENCRYPT_KEY
with 32 random characters string.
- Add middleware multitenancy on the routes that you need;
- Send X-Ref header on request with tenant reference, defined on tenants table.
- Add tenant:
php artisan tenant:add {name?} {reference?} {db_name?} {db_user?} {db_password?} {db_host?} {db_port?}
{reference?} Used to pass on request header to identify tenant
All params are optional, if not present, will be asked on console
- Migrate tenant:
php artisan tenant:migrate {tenant?} {--fresh} {--seed}
{tenant?} Select tenant by id, if not present, all tenants are selected
{--fresh} Is present, will drop all tables from the database
{--seed} Is present, call seeds
- Seed tenant:
php artisan tenant:seed {tenant?} {--class=*}
{tenant?} Select tenant by id, if is not present, all tenants are selected
{--class=*} Is required, specify class name
- Backup tenant:
php artisan tenant:backup {tenant?}
{tenant?} Select tenant by id, if is not present, all tenants are selected
Run the tests with:
vendor/bin/phpunit
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.