私はLumenにリクエストURLに基づいて複数のデータベースを扱うべき小さなアプリケーションを持っています。これを可能にするために、私は/config/というフォルダを作成し、/config/database.phpという設定ファイルを作成しました。ここにコードがあります。私は正確に何をする必要があるかを示すためにいくつかのコメントを追加しました。Call Config ::ルーメン5.4のデータベースを変更するように設定しますか? (Eloquentを使用して)
<?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
を呼び出す必要がありますが、ルーメンに利用可能であるように見えるdoes notの。私はこれらの設定を変更するにはどうすればよい(デフォルトのデータベース接続とそのデータベース)私はこれを可能にする方法がある願ってい
。おかげでたくさん:)次のように使用することができ、クエリで
こんにちはリカルド。ご回答有難うございます。これは素晴らしいですが、私はまだすべてのクライアントが自分のデータベースを持っているので、 "クライアント_ ****"に接続 "クライアント"のデータベースを変更する必要があります。どのようにデータベースを動的に設定できるか知っていますか? – KoalaGangsta