php - change Laravel default user db connection to another db connection -


i have config/database.php follow:

'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'    => '', ), 

),

and i'm using standard laravel 5.3 user authentication.

i tried in registercontroller.php:

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

and still no luck

if move or change db connection 'another' db connection related user (e.g. login, register, forgot pass, etc.), settings need change?

i tried change config/database.php default connection follow:

    'default' => 'another', 

and works, seems need tell/configure somewhere use 'another' db connection user transaction

thanks!

to use different connection specific models only, can set property in model class, e.g. app\user:

class user extends authenticatable {     use notifiable;      protected $connection = 'another';  ... } 

see https://laravel.com/docs/5.3/eloquent#basic-usage


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -