7
Good afternoon guys, I am redoing a system and adopted the Laravel 5. In this system I have several schemas in the database and the solution I found was to work with a connection for each schema, as follows:
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'schema1',
],
'pgsql2' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'schema2',
],
Would there be any other way to do it ?
Is there a way to dynamically create drivers and banks? For example, the user registers into the system and a schema is created just for him. And so on, without the developer or the person responsible worrying about adding manually. + 1
– Giancarlo Abel Giulian
Oops! Come on... To create the Databases you will need the Migrations: http://laravel.com/docs/5.1/migrations. where to create you can call the command by a controller http://laravel-tricks.com/tricks/run-artisan-commands-form-route-or-controller. After you create the database you will be able to store the user and his database name in the main database, when he accesses route to it http://laravel.com/docs/5.1/routing#route-group-sub-Domain-routing you configure his database. Every time you do model operation you can get the db of it on Session.
– juniorb2ss
Example for you here: https://laracasts.com/discuss/channels/laravel/l5-multiple-databases-based-on-subdomein
– juniorb2ss