Sunday, April 16, 2017

How do I log in a user in Laravel?

I'm practicing manual authentication in Laravel for learning purposes, following along laracasts.com and reading the manual user authentication related documentation here - https://laravel.com/docs/5.4/authentication#authenticating-users

My login controller code is as follows:

public function loginSubmit() {
  $email = request('email');
  $password = request('password');

  if (Auth::attempt(['email' => $email, 'password' => $password])) {
    return 'logged in';
  } else {
    return 'not logged in';
  }

Albeit the password not being hashed, I am using the Auth::attempt with the correct email and password information but am not able to return 'logged in'. How can I get the login to work with Auth::attempt ?



via Simon Suh

Advertisement