(Laravel Config::set Persist Through Requests?)Laravel動態數據庫的
得到下面的答案後,我嘗試過了......
'default' => 'mysql_main',
'connections' => [
'mysql_main' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'mysql_company' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => Auth::user()->club->db_name,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
],
然而,在配置下這樣做的database.php文件夾內我收到以下錯誤...
Fatal error: Class 'Auth' not found in F:\trapstats_v5\config\database.php on line 73.
是否有另一種方式做動態的數據庫連接,根據用戶,這將節省救援人員到場呃請求,而不是每次我想訪問動態連接時做config([database.connections.mysql_company.database' => Auth::user()->club->db_name])
?
此問題與Dynamic database connection in Laravel的答案類似。如果我也這樣做的話,我會得到同樣的錯誤,除了這次被稱爲Session而不是Auth。