Implementing Gravatar in Filament is a simple process that allows your users to display their avatars quickly and efficiently. In this tutorial, I'll show you how to do it in just a few steps.
The first step is to modify the User model in your Laravel project. We'll add the necessary interfaces and the function to get the avatar from Gravatar.
use Filament\Models\Contracts\FilamentUser; use Filament\Models\Contracts\HasAvatar; class User extends Authenticatable implements FilamentUser, HasAvatar { public function getFilamentAvatarUrl(): ?string { $hash = md5(strtolower(trim($this->email))); return "https://www.gravatar.com/avatar/{$hash}.jpg?s=80&d=mp"; } }
You can customize the size of the image that Gravatar will return by changing the s parameter in the URL. For example, s=80 indicates a size of 80x80 pixels.
That's it! Once you implement these changes and log back into your Filament dashboard, you'll see that the Gravatar image is displayed correctly for each user.
Implementing Gravatar in Filament is not only easy, but it also improves the user experience by allowing custom avatars without the need to store images on your server. If you have any questions or need further customization, feel free to experiment with the Gravatar URL to adjust it to your needs.
Page loaded in 37.56 ms