PHPackages                             tomshaw/laravel-gravatar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tomshaw/laravel-gravatar

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tomshaw/laravel-gravatar
========================

Gravatar avatars, profiles, and QR codes for Laravel.

v0.8.0(1mo ago)19.6k↓72.3%MITPHPPHP ^8.5CI passing

Since Apr 14Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/tomshaw/laravel-gravatar)[ Packagist](https://packagist.org/packages/tomshaw/laravel-gravatar)[ Docs](https://github.com/tomshaw/laravel-gravatar)[ RSS](/packages/tomshaw-laravel-gravatar/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (9)Dependencies (24)Versions (17)Used By (0)

Laravel Gravatar 📸
==================

[](#laravel-gravatar-)

Gravatar avatars, profiles, and QR codes for Laravel — zero config to start, configurable when you need it.

[![GitHub Workflow Status](https://camo.githubusercontent.com/42f1d2bc02796db54917cdaa1200adc553cb0dbbe85012c96607f7d0e0f2d049/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f6d736861772f6c61726176656c2d67726176617461722f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://camo.githubusercontent.com/42f1d2bc02796db54917cdaa1200adc553cb0dbbe85012c96607f7d0e0f2d049/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f6d736861772f6c61726176656c2d67726176617461722f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265266c6162656c3d7465737473)[![issues](https://camo.githubusercontent.com/f70ad31cf39e8ee02b5aad53a2f04cdb6523f211fc9893188390d6b7b83abc23/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f746f6d736861772f6c61726176656c2d67726176617461723f7374796c653d666c6174266c6f676f3d6170707665796f72)](https://camo.githubusercontent.com/f70ad31cf39e8ee02b5aad53a2f04cdb6523f211fc9893188390d6b7b83abc23/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f746f6d736861772f6c61726176656c2d67726176617461723f7374796c653d666c6174266c6f676f3d6170707665796f72)[![forks](https://camo.githubusercontent.com/10c6a6c62f23a3b549a132ed7bfd628aebcc8d1e8e897d68d500b4b06f107f00/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f746f6d736861772f6c61726176656c2d67726176617461723f7374796c653d666c6174266c6f676f3d6170707665796f72)](https://camo.githubusercontent.com/10c6a6c62f23a3b549a132ed7bfd628aebcc8d1e8e897d68d500b4b06f107f00/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f746f6d736861772f6c61726176656c2d67726176617461723f7374796c653d666c6174266c6f676f3d6170707665796f72)[![stars](https://camo.githubusercontent.com/d7f01e91ee7b0ca4b9efee4614d700c50e4004411bf6790ba4859747c25463a9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f746f6d736861772f6c61726176656c2d67726176617461723f7374796c653d666c6174266c6f676f3d6170707665796f72)](https://camo.githubusercontent.com/d7f01e91ee7b0ca4b9efee4614d700c50e4004411bf6790ba4859747c25463a9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f746f6d736861772f6c61726176656c2d67726176617461723f7374796c653d666c6174266c6f676f3d6170707665796f72)[![GitHub license](https://camo.githubusercontent.com/3d90d152e2f7a56a8fe26bed2167558303965341bec0ad2d6c5cccea39d673d8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f6d736861772f6c61726176656c2d6772617661746172)](https://github.com/tomshaw/laravel-gravatar/blob/master/LICENSE)

 [![blank](https://camo.githubusercontent.com/7f1b18962bf969650f660a8ea0c8d540938e7a2ef56690d677184df223e9fc1b/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026723d7067)](https://camo.githubusercontent.com/7f1b18962bf969650f660a8ea0c8d540938e7a2ef56690d677184df223e9fc1b/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026723d7067) [![mp](https://camo.githubusercontent.com/4c81671f2023b2b115c014b5323f17c5ef973e4a4fadb2d031eec35f1337aba4/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d6d7026723d7067)](https://camo.githubusercontent.com/4c81671f2023b2b115c014b5323f17c5ef973e4a4fadb2d031eec35f1337aba4/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d6d7026723d7067) [![identicon](https://camo.githubusercontent.com/637873a26cda01ec18676fb25d818fe7db390bf6b1229bb9accf59f4dec6faa9/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d6964656e7469636f6e26723d7067)](https://camo.githubusercontent.com/637873a26cda01ec18676fb25d818fe7db390bf6b1229bb9accf59f4dec6faa9/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d6964656e7469636f6e26723d7067) [![monsterid](https://camo.githubusercontent.com/c1f8d95d08c571264f3f523ea9ca291cd90364770aa0c4b912a7300c0c88f103/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d6d6f6e73746572696426723d7067)](https://camo.githubusercontent.com/c1f8d95d08c571264f3f523ea9ca291cd90364770aa0c4b912a7300c0c88f103/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d6d6f6e73746572696426723d7067) [![wavatar](https://camo.githubusercontent.com/11a916f00ba16b48127476154a0f13cff50ee5864adf9c64aef529b66039baed/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d7761766174617226723d7067)](https://camo.githubusercontent.com/11a916f00ba16b48127476154a0f13cff50ee5864adf9c64aef529b66039baed/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d7761766174617226723d7067) [![retro](https://camo.githubusercontent.com/28a682c380029b786f026b6c62965f8679f9a448aecf924ab73f68e27547ecda/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d726574726f26723d7067)](https://camo.githubusercontent.com/28a682c380029b786f026b6c62965f8679f9a448aecf924ab73f68e27547ecda/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d726574726f26723d7067) [![robohash](https://camo.githubusercontent.com/0ea45d557f5c2e4b8dea2011f2f8391ecbd24cc65b9e35a9e2c6cf8bc1dfbd3e/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d726f626f6861736826723d7067)](https://camo.githubusercontent.com/0ea45d557f5c2e4b8dea2011f2f8391ecbd24cc65b9e35a9e2c6cf8bc1dfbd3e/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d726f626f6861736826723d7067) [![blank](https://camo.githubusercontent.com/a2ec5fe6e70ed12a86980e2abd0c4095af1ec3bfeb37ab5bc283f54bc28c61a8/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d626c616e6b26723d7067)](https://camo.githubusercontent.com/a2ec5fe6e70ed12a86980e2abd0c4095af1ec3bfeb37ab5bc283f54bc28c61a8/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f30303030303030303030303030303030303030303030303030303030303030303f733d343026643d626c616e6b26723d7067)

---

- [Installation](#installation)
- [Rendering avatars](#rendering-avatars) — [directive](#the-directive), [component](#the-component)
- [Building URLs](#building-urls) — [facade](#the-facade), [fluent builder](#fluent-builder)
- [Models](#models)
- [Profiles](#profiles)
- [QR codes](#qr-codes)
- [Hashing](#hashing)
- [Testing](#testing)
- [Configuration](#configuration)
- [Parameter reference](#parameter-reference)

Installation
------------

[](#installation)

```
composer require tomshaw/laravel-gravatar
```

That's everything — the package auto-registers and every default is sensible. Publish the config only if you want to change them:

```
php artisan vendor:publish --tag=gravatar-config
```

Rendering avatars
-----------------

[](#rendering-avatars)

### The directive

[](#the-directive)

`@gravatar` outputs a URL, so it goes inside a `src` attribute you write yourself:

```

```

Every parameter is named and optional except `email`.

### The component

[](#the-component)

`` emits the whole `` tag. Because it owns the markup, it can do three things the directive structurally cannot: forward your attributes, add a `2x` `srcset` for high-density displays, and swap in a local image when the browser can't reach Gravatar at all.

```

```

```

```

PropDefaultNotes`email`—Required.`size`configAlso sets `width`/`height`, which your own attributes override.`default` `rating` `secure` `extension` `hash`configAs per [parameter reference](#parameter-reference).`force-default``false`A real boolean here, rather than the directive's `'y'`/`'n'`.`retina``true`Emits the `2x` `srcset`. Skipped automatically when doubling would exceed Gravatar's 2048px ceiling.`fallback`configLocal image swapped in via `onerror`. A relative path resolves through `asset()`.Note that `default` and `fallback` solve different problems. `default` is rendered *by Gravatar*when an address has no avatar, so it needs Gravatar to be reachable. `fallback` is what the browser shows when the request fails outright — a dropped connection, an outage, DNS.

Publish the view to change the markup:

```
php artisan vendor:publish --tag=gravatar-views
```

Building URLs
-------------

[](#building-urls)

### The facade

[](#the-facade)

```
use TomShaw\Gravatar\Facades\Gravatar;

Gravatar::src('email@example.com', size: 200, default: 'retro');
Gravatar::hash('email@example.com');
Gravatar::profileUrl('email@example.com');
Gravatar::qrCode('email@example.com', size: 350);

Gravatar::has('email@example.com');       // bool     — HTTP
Gravatar::profile('email@example.com');   // ?Profile — HTTP
```

### Fluent builder

[](#fluent-builder)

```
Gravatar::for($user->email)->size(200)->retro()->url();
Gravatar::for($user->email)->size(200)->rating('pg')->exists();
```

Each built-in default image is a shorthand — `->mp()`, `->identicon()`, `->monsterid()`, `->wavatar()`, `->retro()`, `->robohash()`, `->blank()`, `->initials()`, `->color()`.

The builder resolves to a URL when cast to a string, so it can be echoed straight into Blade:

```

```

Models
------

[](#models)

```
use TomShaw\Gravatar\Concerns\HasGravatar;

class User extends Authenticatable
{
    use HasGravatar;
}
```

```
$user->gravatarUrl(size: 200, default: 'retro');
$user->gravatarProfileUrl();
$user->gravatarQrCode(size: 350);

$user->hasGravatar();      // HTTP
$user->gravatarProfile();  // HTTP
```

The address is read from the `gravatar.email_column` config value. Override it per-model:

```
protected function gravatarEmailColumn(): string
{
    return 'contact_email';
}
```

Every method is prefixed deliberately. Eloquent resolves bare property access through relations and attribute mutators, so a trait method named `gravatar()` would make `$user->gravatar` throw a `LogicException`. Reach for `Gravatar::for($user->email)` when you want the fluent builder on a model.

Profiles
--------

[](#profiles)

`profile()` returns a `Profile`, or `null` when the address has no Gravatar account.

```
$profile = Gravatar::profile('email@example.com');

$profile->displayName;
$profile->location;
$profile->jobTitle;
$profile->company;
$profile->pronouns;
$profile->verifiedAccounts;

$profile->get('timezone');  // any field, straight from the raw payload
$profile->toArray();        // the whole payload
```

This works with no API key. Gravatar withholds some fields from anonymous callers — timezone, languages, contact info, links, interests, payments, gallery images — and caps verified accounts at four. Set a key to receive full profiles and a higher rate limit:

```
GRAVATAR_API_KEY=your-key
```

Keys are free from [gravatar.com/developers](https://gravatar.com/developers/).

`profile()` and `has()` are the only methods that touch the network, so both cache — misses included, so a missing profile doesn't re-request on every page load. Set `gravatar.cache.ttl` to `0` to disable.

QR codes
--------

[](#qr-codes)

```
Gravatar::qrCode($user->email, size: 350, version: 3, type: 'gravatar');
```

`version` is `1` (standard) or `3` (modern dots). `type` is `default` (no logo), `user` (the user's avatar in the centre), or `gravatar` (the Gravatar logo).

Hashing
-------

[](#hashing)

Gravatar [specifies SHA256](https://docs.gravatar.com/api/avatars/hash/) and explicitly says not to use MD5, which is reversible and can leak the address it was built from. This package defaults to SHA256.

MD5 stays available for URLs generated before the change:

```
Gravatar::src($email, hash: 'md5');
Gravatar::for($email)->md5()->url();
```

Or set `gravatar.hash` to `md5` globally.

Testing
-------

[](#testing)

`Gravatar::fake()` answers `has()` and `profile()` from canned data and makes no HTTP calls. URL building is left alone, since it never hit the network to begin with.

```
use TomShaw\Gravatar\Facades\Gravatar;

$fake = Gravatar::fake(
    profiles: ['ada@example.com' => ['display_name' => 'Ada Lovelace']],
    existing: ['grace@example.com'],
);

expect($user->gravatarProfile()->displayName)->toBe('Ada Lovelace');
expect(Gravatar::has('grace@example.com'))->toBeTrue();
expect(Gravatar::has('nobody@example.com'))->toBeFalse();
```

Emails in `profiles` also report as existing. Lookups are recorded:

```
$fake->assertLookedUp('ada@example.com');
$fake->assertNotLookedUp('someone@example.com');
$fake->assertNothingLookedUp();
```

Configuration
-------------

[](#configuration)

```
return [
    'hash' => 'sha256',            // or 'md5'
    'size' => 80,
    'default' => 'mp',
    'rating' => 'g',
    'secure' => true,
    'extension' => 'jpg',
    'fallback' => null,            // local image for
    'api_key' => env('GRAVATAR_API_KEY'),
    'cache' => [
        'store' => null,           // null uses the app default
        'ttl' => 3600,             // 0 disables
        'prefix' => 'gravatar',
    ],
    'email_column' => 'email',     // read by HasGravatar
];
```

Values passed at a call site always win over config.

Parameter reference
-------------------

[](#parameter-reference)

Accepted by `src()`, the directive, and (minus `email`) the component.

ParameterTypeDefaultAccepts`email``string`—Required.`size``int``80``1`–`2048`.`default``string``mp``mp`, `identicon`, `monsterid`, `wavatar`, `retro`, `robohash`, `blank`, `404`, `initials`, `color`, or a publicly reachable URL.`rating``string``g``g`, `pg`, `r`, `x`.`secure``bool``true`Uses `secure.gravatar.com`.`forceDefault``string``n``y` always loads the default image.`forceExtension``string``jpg``jpg`, `jpeg`, `png`, `gif`, `webp`, or `''` for none.`hash``string``sha256``sha256`, `md5`.Anything outside these throws an `InvalidArgumentException`, so a typo fails loudly at render rather than silently producing a dead URL.

Requirements
------------

[](#requirements)

- PHP 8.5
- Laravel 13.0

Contributing
------------

[](#contributing)

```
composer test      # Pest
composer analyse   # PHPStan
composer format    # Pint
```

License
-------

[](#license)

The MIT License (MIT). See [License File](LICENSE) for more information.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance94

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~75 days

Recently: every ~26 days

Total

12

Last Release

32d ago

PHP version history (5 changes)v0.1.0PHP ^8.0

v0.1.1PHP ^8.1|^8.2|^8.3|^8.4

v0.1.2PHP ^8.2|^8.3|^8.4

v0.2.2PHP ^8.2|^8.3|^8.4|^8.5

v0.4.0PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/14fd02efdbaf6247b61c9846697c86dabcbf430374aeff0d80e509d95d186658?d=identicon)[Tom Shaw](/maintainers/Tom%20Shaw)

---

Top Contributors

[![tomshaw](https://avatars.githubusercontent.com/u/32818?v=4)](https://github.com/tomshaw "tomshaw (58 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")

---

Tags

laravellivewireprofilegravataravatar

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/tomshaw-laravel-gravatar/health.svg)

```
[![Health](https://phpackages.com/badges/tomshaw-laravel-gravatar/health.svg)](https://phpackages.com/packages/tomshaw-laravel-gravatar)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4227.0M133](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21362.6k](/packages/ramonrietdijk-livewire-tables)[lakm/laravel-comments

Integrate seamless commenting functionality into your Laravel project.

40815.8k1](/packages/lakm-laravel-comments)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.8k](/packages/tomshaw-electricgrid)[marcorieser/statamic-livewire

A Laravel Livewire integration for Statamic.

23122.2k16](/packages/marcorieser-statamic-livewire)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1422.0k5](/packages/team-nifty-gmbh-tall-datatables)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
