Hello Devs,

In this tutorial, we are going to learn how to load gravatar image in laravel.

Follow this step by step guide given below:




Step 1 : 


Install Laravel App

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



Step 2 : 


Install Package 

composer require creativeorange/gravatar

config/app.php

'providers' => [
	//....
	'Creativeorange\Gravatar\GravatarServiceProvider::class',
],
'aliases' => [
	//....
	'Gravatar' => 'Creativeorange\Gravatar\Facades\Gravatar::class',
],

Run this command:

php artisan vendor:publish



Step 3 : 


Gravatar Configuration config/gravatar.php

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 routes/web.php

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



Step 5 : 


Create Controller app/http/controller/GravatarController.php

<?php

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
        Gravatar::get('test@example.com');

        // set fallback image
        Gravatar::fallback('https://rathorji.in/.....image_url')->get('test@example.com');
        return view('gravatar');
    }
}



Step 6 : 


 Create Blade File /resources/views/gravatar.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>How to Load Gravatar Image in Laravel? - Rathorji.in</title>
</head>
<body>
    <h1>How to Load Gravatar Image in Laravel? - Rathorji.in</h1>
    <img src="{{ Gravatar::get('test@example.com') }}" alt="No image found">
</body>
</html>

Run this command:

php artisan serve

Open this URL:

http://localhost:8000/gravatar


I hope this example helps you.