Laravel - Authentication - The Authenticatable Contract
Now that we have explored each of the methods on the UserProvider
, let's take a look at the Authenticatable
contract. Remember, user providers should return implementations of this interface from the retrieveById
, retrieveByToken
, and retrieveByCredentials
methods:
This interface is simple. The getAuthIdentifierName
method should return the name of the "primary key" field of the user and the getAuthIdentifier
method should return the "primary key" of the user. When using a MySQL back-end, this would likely be the auto-incrementing primary key assigned to the user record. The getAuthPassword
method should return the user's hashed password.
This interface allows the authentication system to work with any "user" class, regardless of what ORM or storage abstraction layer you are using. By default, Laravel includes a App\Models\User
class in the app/Models
directory which implements this interface.