Closed mr-Sepi0l closed 7 years ago
This is tricky.. The only option I can come up with is to re-bind db.connection
in the module's service provider.... But that would be a "last binder connection wins". And you back to the same problem....
Not sure of this.. Contextual bindings might solve this but you'd have to use the schema builder for dB connections.. No eloquent.
You could create new named connections in /config/database.php
(in the connections
key):
...
'mysql => [
...
],
'myotherconnection' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
...
As an alternative, you can register new connections in your service provider(s) of your module(s).
Eloquent models can specify which connection they use: https://laravel.com/docs/5.3/eloquent#eloquent-model-conventions (scroll down to Database Connection
).
@mikemand oh crap, never seen that - connection per model - while reading the docs
Is there any way to use laravel L5-Modular and apply a new database connection for each module?
Yes, you can programmatically add configuration in laravel, should be documented in their docs.
Hi,
First thanks for your work. I'd like to know if it is or will be possible to have multiple .env by modules or if each modules can be related to another databases.
Thanks