How to Load Gravatar Image in Laravel?

Laravel 6 , Laravel , Laravel 7




Hi Dev,

Today, In this blog, I will learn you how to load gravatar image in laravel. There are several package for Gravatar image for laravel application, but We’re going to use creativeorange/gravatar package. that is i think better.

It is very easy to setup Gravatars on your site. Gvatar is a graphical representation of a user. We will use the e-mail address associated with your account and query Gravatar for your image.

Here I will give you full example for load gravatar image in laravel You can follow bellow step by step.

Step 1 : Install Laravel App

In this step, You can install laravel fresh app. So open terminal and put the bellow command.

composer create-project --prefer-dist laravel/laravel blog

Step 2 : Install Package

In this step, we are going to install creativeorange/gravatar package.So Let's open terminal and run bellow command:

composer require creativeorange/gravatar

After Run successfully above command thenafter we need to add this service provider and aliase in config/app.php file:


'providers' => [




'aliases' => [


'Gravatar' => 'Creativeorange\Gravatar\Facades\Gravatar::class',


Finally Add this service provider and aliase after publish the config by running the bellow command So Let's open terminal and run bellow command:

php artisan vendor:publish

Step 3 : Gravatar Configuration

In this step, we have to need define gravatar size and option in the package config file.


return [

'default' => [

'size' => 80,

'fallback' => 'mm',

'secure' => false,

'maximumRating' => 'g',

'forceDefault' => false,

'forceExtension' => 'jpg',


'small-secure' => [

'size' => 30,

'secure' => true,


'medium' => [

'size' => 150,



Step 4 : Add Route

In this step, we have to add new route in routes file open web.php file add bellow route in routes file.


Route::get('/gravatar', 'GravatarController@gravatar');

Step 5 : Create Controller

In this step, You can create new controller as GravatarController file.So, let's copy bellow code and put on GravatarController.php file.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Creativeorange\Gravatar\Facades\Gravatar;

class GravatarController extends Controller



* Display the specified resource.


* @return \Illuminate\Http\Response


public function gravatar()


// get image


// set fallback image


return view('gravatar');



Step 6 : Create Blade File

In last step. In this step we have to create gravatar blade file. So mainly we have to create gravatar view file. So finally you have to create gravatar following file and put bellow code:


<!DOCTYPE html>



<title>How to Load Gravatar Image in Laravel? -</title>



<h1>How to Load Gravatar Image in Laravel? -</h1>

<img src="{{ Gravatar::get('') }}" alt="No image found">



Now we are ready to run our example so run bellow command for quick run:

php artisan serve

Now you can open bellow URL on your browser:


It will help you...

Recommended Posts