Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to store multiple database connection in my current laravel db. i need to connect these via dropdown and generate reports on the fly. what is the best way to configure this

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
189 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can just create a table "connection(strings)" in your 1st db and create a model for that table.

After that you can do something like this:

$selected = Connection::query()->where('name', 'fromdropdown')->first();
   $connection = $selected;
                config(['database.connections.data' => array(
                    'driver'    => 'sqlsrv',
                    'host' => $connection['Database_Server'],
                    'database' => $connection['Database_Name'],
                    'username' => $connection['Database_User'],
                    'password' => $connection['Database_Pass']

                )]);

                DB::setDefaultConnection('data');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...