Reputation: 702
I have multiple database connection, but for perusahaan db connection I want set database_name from session. how to resolve it?
Upvotes: 1
Views: 1664
Reputation: 28541
You need to do that at runtime, it cannot be done directly from the configuration file.
config(['database.connections.perusahaan.database' => session('db_key')]);
You may also need to purge the connection as it may be cached
app(DatabaseManager::class)->purge('perusahaan');
Upvotes: 0
Reputation: 9381
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.
Upvotes: 2