1

I have multiple database connection, but for perusahaan db connection I want set database_name from session. how to resolve it?

. enter image description here

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.