In my project i have to select, on login, which database i want to use in application until next logout.
I'm thinking in way to save de name of database into a global variable but i don't know how.
In this moment i'm trying to set the database on route:
Route::group(['middleware' => 'auth'], function () {
Route::get('app/groups', function()
{
DB::disconnect();
Config::set('database.default','db2');
DB::reconnect();
return view('app.main-folders');
});
});
I do the the login with db1 and the page was returned to app/groups and it is work, change the database to db2 and show the data but when i select another link it seems that it loses the connection because give me an sql error.
Which is the best option to do that? The selection of the database has to be dynamic.
If i save the database name into a global variable i can use that name to do queries:
DB::connection($name)->select(...);
How can i solve that?
Thanks