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:osI 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:osYou 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');