How to load gravatar image in laravel using laravel-gravatar package

How to load gravatar image in laravel using laravel-gravatar package

Gravatar is a graphical representation of a user. We usually see an image icon or dummy image in the comments of users on the websites. These images are known as gravatar. So here, We are going to see how can we implement or load gravatar image in laravel.

Here, in this tutorial, we will use thomaswelton/laravel-gravatar package to load gravatar image in laravel. Gravatar images actually get from social networking sites or profile image from google on the basis of email id.

Whenever, we will put our email id, gravatar will take out the profile image of that particular email id from social networking websites.

There are Several packages available to get gravatar image, so we can choose onyone of them but here we will use thomaswelton/laravel-gravatar package for this example. 

Step 1: Install Package

In the first step, we will need to install thomaswelton/laravel-gravatar package in our laravel application. So opn you terminal and run the following command to download and install this pachage in our laravel application.

composer require thomaswelton/laravel-gravatar

After downloading the package, we will need to do some configurations to use the feature. So open your applications config/app.php file and add provider and alias in their respective array like below.

'providers' => [

'aliases' => [
  'Gravatar' => Thomaswelton\LaravelGravatar\Facades\Gravatar::class

Step 2: Use of Gravatar Package

After installing and configuring this package, we are able to Gravatar class in our application. There are some methods available in this class.

Gravatar::exists($email) : In this method we will just need to pass email address of any user to check any garavatar is available for this email or not.

Gravatar::src($email, $size = null, $rating = null) : We can use this method to get gravatar  associated with a particular email id and we can also define size and rating. 

We can use these method, in our application like the code given below.

<img src="{{ Gravatar::src('') }}">

<!-- Show image with default dimensions --> <img src="{{ Gravatar::src('') }}"> <!-- Show image at 180px --> <img src="{{ Gravatar::src('', 180) }}">

You can also check out the article for creating country, state,city dependent dropdown in laravel by clicking on the link below.

Laravel dependent country state city dropdown ajax jquery