mk-devs / multi-tenant
Create, migrate and seed different databases dynamiclly without having to change your app connection.
1.1
2019-10-29 20:43 UTC
This package is auto-updated.
Last update: 2025-06-29 01:52:04 UTC
README
Multi-Tenant is a Laravel package that can be used to create, migrate and seed different databases dynamiclly without having to change your app connection.
This is useful for web applications that stores data of each tenant in different database.
Installing
You can install the package via composer:
composer require mk-devs/multi-tenant
The package will register itself automatically.
Usage
Installing the packege on your Laravel project will add MultiTenant class as well as helpful artisan commands.
Artisan Commands
php artisan tenant:create database connection
php artisan tenant:migrate database connection --path
php artisan tenant:refresh database connection
php artisan tenant:rollback database connection
php artisan tenant:seed database connection --class
Available Methods
create
Create a new databaseparams: [database, connection]
migrate
Run migrate for specific databaseparams: [database, connection, path]
refresh
Reset and re-run all migrationsparams: [database, connection]
rollback
Rollback the last database migrationparams: [database, connection]
seed
Run seed for specific databaseparams: [database, connection, class]
set
Change app database connection in run timeparams: [database, connection]
Params
Param | Required | Default |
---|---|---|
database | true | null |
connection | false | Current connection |
class | false | null |
path | false | null |
Use Cases
// Simple examples MultiTenant::migrate('database_name'); MultiTenant::create('database_name')->migrate(); MultiTenant::seed([ 'database' => 'database_name', 'connection' => 'mysql', 'class' => 'CustomersTableSeed' ]); MultiTenant::set([ 'database' => 'database_name', 'connection' => 'mysql', ]); // Advanced example MultiTenant::migrate([ 'database' => 'database_name', 'connection' => 'mysql', 'path' => '/database/migrations/tenant' ])->seed(['class' => 'CustomersTableSeed'])->set();
License
Multi-Tenant is open-sourced software licensed under the MIT