I am using Laravel with FilamentPhp and as per requirements I changes default "name" to "username" in my migration and when I login I am getting errors because I changed name to username and If I update the name to username in vendor filamentmanager.php then It's working but it's bad practise
Filament\FilamentManager::getUserName(): Return value must be of type string, null returned
How can I override that function from this
public function getUserName(Model | Authenticatable $user): string
{
if ($user instanceof HasName) {
return $user->getFilamentName();
}
return $user->getAttributeValue('name');
}
to this
public function getUserName(Model | Authenticatable $user): string
{
if ($user instanceof HasName) {
return $user->getFilamentName();
}
**return $user->getAttributeValue('username');**
}
Please advice, I tried creating custom service provide but not succeed.
Filament did that for you, there's no need to override anything.
Custom behavior can be achieved with the help of below lines of core code:
This means Filament checks whether your model implements that interface. If implemented, it will use the interface method to return a custom value instead of the default name column.
First, your User model class needs to implement
HasName
interface, then you must implement the interface's method to return your desired value.Here's an example: