I have a series of databases named server_1 to server_100. Based on the URL parameter that the users select, I would like to connect to that database. Is there a way to accomplishing this without defining 100 separate connections in .env?
CodePudding user response:
You have to change database connection on fly and also dont forget to purge connection.
Config::set("database.connections.mysql.host", "127.0.0.1");
Config::set("database.connections.mysql.database", "database_name");
Config::set("database.connections.mysql.username", "username");
Config::set("database.connections.mysql.password", "password");
DB::purge('mysql');