3

I have config/database.php as 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 my registercontroller.php:

protected function create(array $data)
{

    $user = new user();
    $user->setConnection('another');
    ...
}

and still no luck

if i like to move or change the db connection into 'another' db connection for anything related with user (e.g. login, register, forgot pass, etc.), where is the settings that i need to change?

I just tried to change my config/database.php default connection as follow:

    'default' => 'another',

and it works, so it seems like i need to tell/configure somewhere that to use 'another' DB connection for any user transaction

Thanks!

4
  • 1
    Check the doc. Also, check the /config/auth.php file. Commented Sep 22, 2016 at 15:12
  • @TheAlpha Thanks for the comments, but it still didn't ring a bell to me... i can't see any sb connections settings there... Commented Sep 22, 2016 at 15:17
  • read this stackoverflow.com/questions/39001288/… Commented Sep 22, 2016 at 16:14
  • Why are you using a different database connection for users? Commented Sep 25, 2016 at 11:50

2 Answers 2

2

To use a different connection for specific models only, you can set a property in your 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

Sign up to request clarification or add additional context in comments.

Comments

0

go to app>auth.php

and edit the table configuration:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.