I am trying to authenticate users in my Laravel application.
I am encountering the following problem:
The problem is your implementation of getAuthIdentifier()
. This method should actually return the primary key of your table and not the username that's used for logging in.
So yours should look like this:
public function getAuthIdentifier(){
return $this->id;
}
Or actually, I recommend you clean up your model a bit more since all of the getSomeAuthStuff
methods are implemented in the two traits.
Use the default model on github as a base and add all your custom code (roles methods, rules etc)
The value returned from getAuthIdentifier()
will be stored in the session.
When using check()
afterwards, retrieveById
will be called on the UserProvider
. And the EloquentUserProvider
does this:
public function retrieveById($identifier)
{
return $this->createModel()->newQuery()->find($identifier);
}
It uses find()
which searches for the model by it's primary key (usually id
)