How to check credentials before authenticating to Laravel 5.3?

Asked

Viewed 345 times

3

My application uses Laravel’s ready authentication, but I need users to log in from a web service.

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

The problem is that before authenticating, I need to check if it exists in the bank and I would like to know if there is any method native to Laravel that I can do this (without consulting with DB::select()).

1 answer

3


You can use the method attempt of the component of Auth for that reason.

With this method it will already perform the authentication for you, without having to redirect again 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.

  • It worked, had even looked at this method in the documentation, but had not understood right how it works. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.