Reputation: 33
I want to change the default database in laravel on change of a session key lets say, by default the session key is 'ff' => '20'
and the default db is 'default' => env('DB_CONNECTION', 'mysql')
and now when I change the value of session key from 'ff' => '20'
to 'ff' => '21'
I want to change the default db to 'default' => env('DB_CONNECTION', 'mysql2')
for all the subsequent request till I don't change the session key again.
I am using laravel 5.5
Upvotes: 2
Views: 2180
Reputation: 1639
use config()
helper from laravel.
to set new config for default database connection, do:
config()->set('database.default', 'mysql2');
Upvotes: 1