Customizing Username field in FilamentPHP Panels

Published on April 30, 2024. Last updated on January 23, 2025.
Customizing Username field in FilamentPHP Panels

If you've used a different field for the user's name, such as username instead of name, you may have encountered an error stating that the name field is not present on the User model.

 

To resolve this issue, you need to implement Filament's HasName contract in your User model.

use Filament\Models\Contracts\HasName;

class User extends Authenticatable implements FilamentUser, HasName
{
    //....
    public function getFilamentName(): string
    {
        return $this->username;
    }

Filament will now use the getFilamentName() method to retrieve the user's name.