vlauciani's avatar

Auth - PasswordController uses wrong DB Connection

Hi

I've two database connections; one (the default) for my data that is MySQL and another one for Auth that is sqlite.

The auth db was created with command:

php artisan migrate --database=sqlite

To use the sqlite db for Auth, I've changed the validator method into AuthController.php class, adding sqlite.users string:

    protected function validator(array $data)
    {      
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:sqlite.users',
            'password' => 'required|min:6|confirmed',
        ]);
    }

The problem now, is that when I hit to Send Password reset link, Laravel uses the MySQL connection instead of sqlite.

How I have to update/change the PasswordController.php file to change the DB connection?

Thank you.

0 likes
2 replies
nickywest's avatar

The password reset stuff comes from Illuminate\Auth\Passwords\PasswordResetServiceProvider, Illuminate\Auth\Passwords\DatabaseTokenRepository, Illuminate\Auth\Passwords\TokenRepositoryInterface, and Illuminate\Auth\Passwords\PasswordBrokerManager (maybe more).

To make big changes to how password resets are handled, you might need to extend these and override some methods.

Just changing the DB connection for password resets shouldn't be that much work though...

PasswordBrokerManager is instantiating DatabaseTokenRepository and passing in the DB connection as seen here

It's using app['db']->connection(); Which is going to be the current connection...

Huh...

It might be that if your user model has the $connection specified that would work... alternatively, changing the default connection in PasswordController...

I'm out of time to investigate further, but I'm posting because I think this might be useful for you to debug further?

Please or to participate in this conversation.