This Package will help you to Generate Gravatar URL's with Laravel.
You can install the package via composer:
composer require remzikocak/laravel-gravatar
Get Users Gravatar URL:
Gravatar::url('test@example.com');
Get Users Gravatar with Custom Configuration:
Gravatar::for('test@example.com')
->size(150)
->default('identicon')
->rating('x')
->get();
Get HTML Image Tag:
Gravatar::img('test@example.com')
Get HTML Image Tag with attributes:
Gravatar::img('test@example.com', [
'class' => 'w-10 h-10 rounded-full'
])
Check if Gravatar for an email exists:
Gravatar::exists('test@example.com')
Get Gravatar using 'HasGravatar' trait:
First add 'HasGravatar' trait to your User Model.
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use RKocak\Gravatar\Traits\HasGravatar;
class User extends Authenticatable
{
use Notifiable, HasGravatar;
after adding the Trait, you can use it like this
$user = App\User::find(1);
// This will return the Gravatar URL
$user->getGravatar();
// or get the Generator instance with preset email
$generator = $user->getGravatarGenerator();
The MIT License (MIT). Please see License File for more information.