I have secondary connection that comes dynamically and here is it's code

 'userdb' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', ''),
            'port' => env('DB_PORT', '3306'),
            'database' => DYNAMIC_DATABASE_NAME,
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => false,

So, once use logged in I want to update update this database dynamically and reconnect to this userdb.

I have used following code but this is not giving persistent DB connection I have to this this everytime manually. Any suggestions ?

config(['database.connections.userdb.database' => 'test']);

1 Answers

Jignesh Joisar On

1.first set database name


2.after set database name you need to purge the DB cache


3.set default connection after u purge db cache