Tricks

Custom user avatar

Sep 20, 2022
Hatim El Oufir
Integration, Admin panel

We all know that Filament comes with a \Filament\AvatarProviders\UiAvatarsProvider that uses the https://ui-avatars.com/ api to generate your users avatar. And of course, we can customize it by creating our own providers class.

But to make it more simple, you can use the package devaslanphp/filament-avatar that comes configured with the same ui-avatar provider and a gravatar provider, but also provider other options to make ui-avatar have dynamic background for example.

To use it, follow the steps below:

  1. Install the package on your project: composer require devaslanphp/filament-avatar
  2. Publish the package configuration file: php artisan vendor:publish --tag=filament-avatar-config
  3. Update the filament default avatar provider in config/filament.php file:
'default_avatar_provider' => \Devaslanphp\FilamentAvatar\Core\FilamentUserAvatarProvider::class,

That's it, now you can switch between ui-avatar and gravatar providers by simply updating the default_provider config on the config/filament-avatar.php file:

'default_provider' => 'ui-avatar'

As I mentioned above, this package can generate the ui-avatar with dynamic background color, by default this option is enabled on config('filament-avatar.providers.ui-avatar.dynamic_bg_color'), you can disable it if you want and specify you static background color in config('filament-avatar.providers.ui-avatar.bg_color').

More information about the package: devaslanphp/filament-avatar

No comments yet…