由於我形象你正在與不同的實體工作,只需通過定義連接的名稱protected $connection
屬性指定他們在模型中每個人的連接。
您可以通過在config/database.php
中定義它來創建新連接。
像這樣:
class Model_One extends Entity
{
protected $connection = "database_one";
[...]
class Model_Two extends Entity
{
protected $connection = "database_two";
[...]
'connections' => [
'database_one' => [
'driver' => 'mysql',
'host' => env('DB_ONE_HOST', 'host_one'),
'port' => env('DB_ONE_PORT', 3306),
'database' => env('DB_ONE_DATABASE', 'database_one'),
'username' => env('DB_ONE_USERNAME', 'username'),
'password' => env('DB_ONE_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => env('DB_ONE_PREFIX', ''),
'timezone' => env('DB_ONE_TIMEZONE', '+00:00'),
'strict' => false,
],
'database_two' => [
'driver' => 'mysql',
'host' => env('DB_TWO_HOST', 'host_two'),
'port' => env('DB_TWO_PORT', 3306),
'database' => env('DB_TWO_DATABASE', 'database_two'),
'username' => env('DB_TWO_USERNAME', 'homestead'),
'password' => env('DB_TWO_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => env('DB_TWO_PREFIX', ''),
'timezone' => env('DB_TWO_TIMEZONE', '+00:00'),
'strict' => false,
]
],
簡單。你不能 – e4c5