将Laravel默认用户db连接更改为另一个db连接


change Laravel default user db connection to another db connection

我有config/database.php如下:

'default' => 'web',
'connections' => array(
# Our primary database connection
'web' => array(
    'driver'    => 'mysql',
    'host'      => 'host1',
    'database'  => 'database1',
    'username'  => 'user1',
    'password'  => 'pass1'
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),
# Our secondary database connection
'another' => array(
    'driver'    => 'mysql',
    'host'      => 'host2',
    'database'  => 'database2',
    'username'  => 'user2',
    'password'  => 'pass2'
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

),

,我正在使用标准的laravel 5.3用户身份验证。

i tried in my registercontroller.php:

protected function create(array $data)
{
    $user = new user();
    $user->setConnection('another');
    ...
}

仍然没有运气

如果我想移动或更改数据库连接到'另一个'数据库连接与用户(例如登录,注册,忘记通行证等),我需要改变的设置在哪里?

我只是试图改变我的config/database.php默认连接如下:

    'default' => 'another',

,它的工作,所以似乎我需要告诉/配置的地方,使用'另一个' DB连接的任何用户事务

谢谢!

要为特定的模型使用不同的连接,可以在Model类中设置一个属性,例如App'User:

class User extends Authenticatable
{
    use Notifiable;
    protected $connection = 'another';
 ...
}

看到https://laravel.com/docs/5.3/eloquent基本用法

go to app>auth.php

和编辑表配置:

 'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'your_table_here',
            'expire' => 60,
        ],
    ],