Download the PHP package tomshaw/laravel-gravatar without Composer
On this page you can find all versions of the php package tomshaw/laravel-gravatar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-gravatar
Laravel Gravatar 📸
Gravatar avatars, profiles, and QR codes for Laravel — zero config to start, configurable when you need it.
- Installation
- component
- fluent builder
- Models
- Profiles
- QR codes
- Hashing
- Testing
- Configuration
- Parameter reference
Installation
That's everything — the package auto-registers and every default is sensible. Publish the config only if you want to change them:
Rendering avatars
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
<x-gravatar /> emits the whole <img> 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.
| Prop | Default | Notes |
|---|---|---|
email |
— | Required. |
size |
config | Also sets width/height, which your own attributes override. |
default rating secure extension hash |
config | As per 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 |
config | Local 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:
Building URLs
The facade
Fluent builder
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
The address is read from the gravatar.email_column config value. Override it per-model:
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
profile() returns a Profile, or null when the address has no Gravatar account.
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:
Keys are free from 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
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
Gravatar specifies SHA256 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:
Or set gravatar.hash to md5 globally.
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.
Emails in profiles also report as existing. Lookups are recorded:
Configuration
Values passed at a call site always win over config.
Parameter reference
Accepted by src(), the directive, and (minus email) the component.
| Parameter | Type | Default | Accepts |
|---|---|---|---|
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
- PHP 8.5
- Laravel 13.0
Contributing
License
The MIT License (MIT). See License File for more information.