This example shows how any registered user can have its own database for one instance of an application with the Laravel Framework.
This kind of apps are called Multi-Tenant Applications because they use Multi-Tenant Data Architecture.
Using the power of Laravel 5 this demo:
- Creates a new database for a registered user with a base schema (running a set of migrations)
- Lets an authenticated user to access his own database data.
Any new model intended to be used on any database must set the connection property like this:
OtherModel.php
protected $connection = 'tenantdb';
Any new migration intended to be part of the base schema for any database must be placed in:
database/migrations/tenant
- Clone the Repo:
git clone https://github.com/uxweb/laravel-multi-db.git laravel-multi-db
- Install Dependencies:
cd laravel-multi-db composer install
- Run Migrations:
php artisan migrate
- Serve the app locally:
php artisan serve
Middleware Used to set the connection's database to the user's own database.
Filesystem Used to create an empty database on user registration.
Configuration Facade. Used to change a connections default database in configuration.
Artisan CLI. Used to run migrations/seeders on the user's own database.
Thank you for considering contributing to this little project!.
This project is open-sourced software licensed under the MIT license