Override user initials #18192
Answered
by
leandrocfe
gregoryloichot
asked this question in
Help
-
PackagePanel builder Package Versionv4 How can we help you?Hello everyone, I wanted to know if, to your knowledge, there is a way to override the method that generates user initials (which are displayed in the profile menu, for example)? Typically, I would like a user with a compound name: John Doe-Smith to have the initials JDS (and not "JD"). Is this possible? Thank you. |
Beta Was this translation helpful? Give feedback.
Answered by
leandrocfe
Oct 13, 2025
Replies: 1 comment 1 reply
-
ui-avatars.com supports
use Filament\AvatarProviders\UiAvatarsProvider;
use Filament\Facades\Filament;
use Filament\Support\Colors\Color;
use Filament\Support\Facades\FilamentColor;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
class CustomUiAvatarsProvider extends UiAvatarsProvider
{
public function get(Model|Authenticatable $record): string
{
$name = str(Filament::getNameForDefaultAvatar($record))
->trim()
->explode(' ')
->join('+');
return str('https://ui-avatars.com/api/?name=')
->append($name)
->append('&color=FFFFFF&background=')
->append(FilamentColor::getColor('gray')[950] ?? Color::Gray[950])
->append('&length=3');
}
} Add this provider in your panel return $panel
->defaultAvatarProvider(CustomUiAvatarsProvider::class) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
gregoryloichot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ui-avatars.com supports
length
. You can customize the default provider:CustomUiAvatarsProvider.php