Laravel : Auth::user() returns null

2019-09-09 06:07发布

问题:

I want to do Auth::user() but before that I must do Auth::attempt() but it always returns false because the attempt() method uses ID to look for the user I am are trying to login. But in my users table I don't have a ID field rather I have user_id field. So is there a way to make the attempt() method use user_id to look up for id in my users table. (Hope I made some sense )

if(!Auth::attempt(Request::only(['username','password']))){  //returns false
     return redirect($this->redirectPath);   /// redirect to login page
}else{
     return redirect($this->redirectTo);   /// redirect to user list page
}