Tim Habersack

Where I put my things..

Laravel; Auth::attempt() works but user not logged in.

May 8th 2014

This was a funky problem that took me a while to figure out.

When a user was logging in, the Auth::attempt() was returning true if there were good credentials passed. However! Using Auth::check() or any other Auth method showed the user wasn't actually logged in. What the heck?

After much hunting, I found this answer on Stack Overflow.

The problem is you have used "userId" as your primary id - but you have not told Laravel.

I realized I did NOT use id as the id for the users table, I went with uid because I thought it made more sense. That's fine, but then you need to tell your Users model what the primary key is by adding this line.

protected $primaryKey = "[your-primary-key-here]";

If you were searching and having this issue, I hope it helped!