Skip to content

Latest commit

 

History

History
51 lines (50 loc) · 2.35 KB

README.md

File metadata and controls

51 lines (50 loc) · 2.35 KB

Multi Tenant Database Laravel With Orchestra Package Implementation

Note

If you are looking for Configuration Tenant Driver for Single Database, Please Click here.

Installation Instruction - Multi Database Connection Setup

Clone or Download the Repository to the htdocs / www folder.

Update Composer by typingComposer update in the command line on the root directory of project. Change default database configuration in config/database.php
We are using default database connection mysql
'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'), //This database will be the root for all other databases, can manage other databases tables etc
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

Database Connection Resolver

'mybuild' => [                         //set up for database connection resolver
            'driver'    => 'mysql',
            'host'      => 'localhost',     // for user with id=1
            'database'  => '',     // for user with id=1
            'username'  => 'root', // for user with id=1
            'password'  => '', // for user with id=1
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

mybuild will be resolved by app\Providers\AppServiceProvider.php in boot method

public function boot()
{
    Tenanti::connection('mybuild', function (Site $entity, array $config) {
        $config['database'] = "mybuild_{$entity->getKey()}"; 
        // refer to config under `database.connections.tenants.*`.
        return $config;
    });
}

Run migration by typingphp artisan migratein the command line

Please feel free to contribute and send pull request.