我在 Lumen 中有一个小应用程序,它应该根据请求 URL 处理多个数据库。为了首先实现这一点,我创建了一个文件夹 /config/ 和一个名为 /config/database.php 的配置文件。这是代码,我添加了一些注释来说明我到底需要做什么。
<?php
return [
'migrations' => 'home',
'default' => 'home',
'connections' => [
// This is the default option and its needed to check if the "client" exists.
'home' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'home',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
// When the client is found in the "home" connection, I'd like to continue with this database settings as default.
'client' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'client_', // There is one database per client which in the end will look like this: "client_******", so I have to add this using Config:set...
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
],
];
我必须调用 Config::set
来更改这些设置,但它似乎在 Lumen 上不可用。我如何更改这些设置(默认数据库连接 及其数据库)
我希望有办法让这成为可能。非常感谢:)
最佳答案
我找到了解决方案。
要设置和编辑您的配置,请使用以数组作为参数的“config”辅助方法。
例子:
config(['database.default' => 'your_connection']);
关于database - 在 Lumen 5.4 中调用 Config::set 来更改数据库? (使用 Eloquent ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45851189/