jeudi 3 septembre 2015

Change DB connection before authenticating user in laravel 5

I want to manually authenticate a user in Laravel 5. My application uses 2 databases, which are located on the same server. In my application i already switch connections in the models or query builder, which works perfect.

But now i want to use laravels Auth::attempt method to login a user. But the credentials for this user are stored in the second database.

In the user model i have: protected $connection = 'first_database'; This is the database it normally should use. But for this 'special' login, i want the user model to use the second_database.

Is this possible?

What i tried:

     \Config::set('database.default', 'second_database');

    // Login this user while using the second_database
    if(\Auth::attempt(['email'=>\Request::get('email'), 'password'=>\Request::get('password')]))
    {
        dd('Success');
    }

But unfortunately, this doesn't work. I`m using Laravel 5.1



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1EDumjx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire