I have multiple database connection, but for perusahaan db connection I want set database_name from session. how to resolve it?
2 Answers
You could do this:
config(['database.connections.perusahaan.database' => session('db_key')]);
You set a config variable runtime with the config helper by passing a value to it from the session helper. The way you do it fails, because session is not yet available while reading config.
I would like to add a warning that you might trust data that should not be trusted, however I do not know enough about your app to be certain.
