Gravatar is a service that offers distinctive worldwide avatars and has integrated it into their blogging platform WordPress.com. If they have registered on WordPress.com and you don't have an avatar image, you can receive a Gravatar src image from their email. Therefore, it is quite simple to implement in your Laravel application. There are a number of packages for using Gravatar images with Laravel, but we'll pick the one that's, in my opinion, the best: thomaswelton/laravel-gravatar.
Installation Package
composer require thomaswelton/laravel-gravatar
Once this package has been installed, enter the config/app.php file and add the service provider and alias.
config/app.php
'providers' => [
....
Thomaswelton\LaravelGravatar\LaravelGravatarServiceProvider::class,
],
'aliases' => [
....
'Gravatar' => Thomaswelton\LaravelGravatar\Facades\Gravatar::class
],
Okay, so here's how we can use Gravatar in our blade file:
Use In Blade File
You can use it in your application now by doing as follows:
If the $email is linked to Gravatar, Gravatar::exists($email) will return boolean, informing you of the situation.
The whole URL for the Gravatar registered email address will be returned by the command Gravatar::src($email, $size = null, $rating = null).
<img src="{{ Gravatar::src('info@codesolutionstuff.com', 200) }}">
We hope that the code and information in this post will help you use the thomaswelton/laravel-gravatar package to load a gravatar image in Laravel 9. If you require assistance or have any comments or suggestions regarding this post, please share them in the comment area.