How do I check credentials before logging in to Laravel 5.3?

3

My application uses Laravel's ready authentication, however I'm requiring users to log in to it from a webservice.

So what I'm trying to do is that if the guy exists in the application database, he does Laravel's native authentication, if not, then I use the webservice.

The problem is that before authenticating, I need to check if it exists in the database and I would like to know if it has some native Laravel method so I can do this (without being a query with DB::select() ).

    
asked by anonymous 11.01.2017 / 21:19

1 answer

3

You can use the attempt method of the Auth component for this.

With this method it will already authenticate for you, without redirecting back to the native method.

public function authenticate($email, $password)
{
    // No lugar do helper você pode usar a Facade também

    if (auth()->attempt(['email' => $email, 'password' => $password])) {
        // Authentication passed...
        return redirect()->intended('dashboard');
    }

    // Loga pelo webservice
}

More details in the documentation .

    
11.01.2017 / 23:13