i think you have something wrong in your database conception , why you must have many databases ? if you cannot change, i think you should use two different laravel project for each database and make communication between them by API .
Using Multi Database (one of them defined in .env orher one is dynamic according to client)
I am working on a project in Laravel 10.x. I am trying to use multiple databases (mysql) in my project. The definition for one of these databases is in the .env file. The other database will be determined based on the database ID entered by the user when logging in. However, the other database that has been determined will be the default connection for all models in my project except for the ClientModel. In other words, for all models except ClientModel, the default connection will be database.connections.mysql.database = $ClientSelectedDatabaseId. ClientModel has a predefined constant for this model, and the protected $connection definition uses this connection. My problem is that after the user logs in, all routes under the /admin route will be protected with the auth middleware, and the database.connections.mysql connection will not be purged or reconnected on every page transition or refresh. I use Redis as the session provider. When the session times out, due to the cookie, the user loses the dynamic connection, resulting in a "no selected database" error. What steps should I follow to resolve this error and structure the project correctly?
Please or to participate in this conversation.