joaovdiasb/laravel-multi-tenancy

Laravel multi-tenancy package

0.2 2023-09-14 13:23 UTC

This package is auto-updated.

Last update: 2024-04-14 14:33:56 UTC


README

Software License CI Total Downloads

Installation

Install via composer

composer require joaovdiasb/laravel-multi-tenancy

Configuration

  1. Publish provider and migrate:
php artisan vendor:publish --provider="Joaovdiasb\LaravelMultiTenancy\LaravelMultiTenancyServiceProvider" && php artisan migrate --path=./database/migrations/tenant
  1. Add env variable TENANT_ENCRYPT_KEY with 32 random characters string.

Usage

  1. Add middleware multitenancy on the routes that you need;
  2. 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.