Hey there!
This is what I have done. In my .env file, I have set the default db connection:
DB_CONNECTION=CONNECTION1
And, in config/database.php,
I have:
'connections' => [
'CONNECTION1' => [
'driver' => 'mysql',
'host' => 'host1',
'port' => 'port1',
'database' => 'database1',
'username' => 'username1',
'password' => 'password1',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'CONNECTION2' => [
'driver' => 'mysql',
'host' => 'host2',
'port' => 'port2',
'database' => 'database2',
'username' => 'username2',
'password' => 'password2',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
Then, in my model, I use,
DB::connection('CONNECTION1')->table('test');
DB::connection('CONNECTION2')->table('test2');
PS: I am also a beginner in Laravel and my suggestion might not be optimal. :-)
Thanks.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community