laravel Change Database connection run time

前端 未结 4 1764
-上瘾入骨i
-上瘾入骨i 2020-12-24 14:48

I need to change laravel 5 database connection in run time.

Do you have any idea about it?

Please share with me.

Thanks.

4条回答
  •  再見小時候
    2020-12-24 15:28

    You can change the connection details during run time using

    Config::set('database.connections.mysql.database', 'other_database');
    

    but don't forget to run purge before in order to delete the cache

    DB::purge('mysql');
    

提交回复
热议问题