Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What is the Authenticable contract in Fortify?
    laravel fortify


What is the Authenticable contract in Fortify?


The Authenticable contract in Laravel Fortify is a contract located at `Illuminate\Contracts\Auth\Authenticatable`. It defines a blueprint of what the `UserProvider` facade should implement.

The Authenticable contract looks like this:

php
namespace Illuminate\Contracts\Auth;

interface Authenticatable
{
    public function getAuthIdentifierName();
    public function getAuthIdentifier();
    public function getAuthPassword();
    public function getRememberToken();
    public function setRememberToken($value);
    public function getRememberTokenName();
}

The key points about the Authenticable contract are:

1. Purpose: It allows the authentication system to work with any "user" class that implements this contract, regardless of the ORM or storage layers used.

2. Default Implementation: By default, Laravel's `App\Models\User` model implements this Authenticable contract.

3. Configuration: In the `config/auth.php` file, you can specify the `provider` that should be used for the `users` guard, which typically points to the `App\Models\User` class.

php
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],
],

4. Flexibility: The Authenticable contract provides a standardized way for the authentication system to interact with user models, allowing you to use any custom user model that implements this contract.

By implementing the Authenticable contract, your user model can be used seamlessly with Laravel's authentication system, including Fortify, Jetstream, and other authentication-related features and libraries.

Citations:
[1] https://jetstream.laravel.com/features/authentication.html
[2] https://laracasts.com/discuss/channels/laravel/laravel-jetstream-login
[3] https://kinsta.com/blog/laravel-authentication/
[4] https://jetstream.laravel.com/features/two-factor-authentication.html
[5] https://jetstream.laravel.com/features/api.html