laravel中一个模型怎么使用多个数据库
展开全部
,
'mysql_center' => [
'driver' => 'mysql',
'host' =>顷郑睁 env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE_CENTER', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' =>丛察 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' =>雀岁 false,
],
我自己建立的model User.php 是可以通过下面这种方式切换数据库的。
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
protected $connection = 'mysql_center';
'mysql_center' => [
'driver' => 'mysql',
'host' =>顷郑睁 env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE_CENTER', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' =>丛察 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' =>雀岁 false,
],
我自己建立的model User.php 是可以通过下面这种方式切换数据库的。
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
protected $connection = 'mysql_center';
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询