laravel中间件动态修改连接数据库

\Config::set('database.connections.mysql.host',$project_db_setting->host);

\Config::set('database.connections.mysql.port',$project_db_setting->port);

\Config::set('database.connections.mysql.database',$project_db_setting->database);

\Config::set('database.connections.mysql.username',$project_db_setting->username);

\Config::set('database.connections.mysql.password',$project_db_setting->password);


//下面这句很重要,要重连下数据库,要不然,连的还是原数据库

\DB::reconnect();

你可能感兴趣的:(laravel中间件动态修改连接数据库)