Support the ongoing development of Laravel.io →
Configuration Database Installation
Last updated 2 years ago.
0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

samantaba samantaba Joined 26 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.