joaovdiasb / laravel-multi-tenancy
Laravel multi-tenancy package
Requires
- php: ^7.4
- doctrine/dbal: ^3.0
- illuminate/support: ^8.0
Requires (Dev)
- mockery/mockery: ^1.0
- nunomaduro/collision: ^4.0
- orchestra/database: ^6.0
- orchestra/testbench: ^6.0
- phpunit/phpunit: 9.4
- symfony/thanks: ^1.0
This package is auto-updated.
Last update: 2024-11-14 15:42:17 UTC
README
Installation
Install via composer
composer require joaovdiasb/laravel-multi-tenancy
Configuration
- 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.
Usage
- Add middleware multitenancy on the routes that you need;
- Send X-Ref header on request with tenant reference, defined on tenants table.
Commands
- 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
Testing
Run the tests with:
vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email j.v_dias@hotmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.