We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Out of the box, Filament uses ui-avatars.com to generate avatars based on a user's name. To provide your own avatar URLs, you can implement the HasAvatar
contract.
So, if you want to support gravatar.com, you can start with creating a custom AvatarProvider.
<?php
namespace App\Filament\AvatarProviders;
use App\Models\User;
use Filament\AvatarProviders\Contracts\AvatarProvider;
use Illuminate\Database\Eloquent\Model;
class GravatarsProvider implements AvatarProvider
{
public function get(Model $authUser): string
{
/** @var User $user */
$user = $authUser;
$hash = md5(strtolower(trim($user->email)));
return "https://www.gravatar.com/avatar/{$hash}.jpg";
}
}
Once you have this, it is as simple as registering it in config/filament.php
under the key default_avatar_provider
:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Avatar Provider
|--------------------------------------------------------------------------
|
| This is the service that will be used to retrieve default avatars if one
| has not been uploaded.
|
*/
'default_avatar_provider' => App\Filament\AvatarProviders\GravatarsProvider::class,
];
Important to know is that if null
is returned from the getFilamentAvatarUrl()
method, Filament will fall back to ui-avatars.com.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.