Hi, I am searching over the Internet regarding the use of multiple database connections and have found solutions that allow me to first create a connection in database.php and then I can switch them as needed. Now the problem is that I do not know about the database names at runtime. I have a primary database that allows the user to log in, and then the database will determine which database will switch based on the user's login.
What I tried:
Config::set('database.connections.mysql.database', Config::get('database.connections.mysql.database') . '_business_' . $preUser->business_id);
This is what I did earlier, and my code worked on the local environment, but when I switched to my development environment, it stopped working.
Any idea why
Another problem that I get is that I want to start migrations and sowing using the same script. I will have a series of databases in the array and you will need to perform a migration on each of them.
I tried this solution too, but it does not work. it shows null when I try to get a database connection after installing it
Laravel: dynamically connect to databases
source
share