Download the PHP package martian/laravatar without Composer
On this page you can find all versions of the php package martian/laravatar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download martian/laravatar
More information about martian/laravatar
Files in martian/laravatar
Package laravatar
Short Description Avatar URLs for Laravel models from Gravatar, DiceBear, UI Avatars, Boring Avatars, Vercel, RoboHash and Unavatar
License MIT
Homepage https://github.com/amplifiedhq/laravatar
Informations about the package laravatar
Laravatar
🚀 A lightweight Laravel package that adds avatars to your Eloquent models. It builds avatar URLs from Gravatar, DiceBear, UI Avatars, Boring Avatars, Vercel Avatar, RoboHash or Unavatar, and you can plug in your own.
[!WARNING] v2.0 is a breaking release. It requires PHP 8.2+ and Laravel 12+, and the driver API, config file, and exceptions have changed. If you use v1, read Upgrading from v1 before you update.
Supported Avatar Drivers
| Driver | Config key | Style | Identifier |
|---|---|---|---|
| Gravatar | gravatar |
The user's own Gravatar, with a generated fallback | |
| DiceBear | dicebear |
31 illustrated styles (API 10.x) | Any string |
| UI Avatars | ui-avatars |
Initials on a colored background | Name |
| Boring Avatars | boringavatar |
Abstract SVG shapes | Any string |
| Vercel Avatar | vercel |
Gradients | Any string |
| RoboHash | robohash |
Robots, monsters, cats, and more | Any string |
| Unavatar | unavatar |
The user's real avatar from 99 social and email providers | Email, username, or domain |
[!NOTE] Unavatar allows 25 anonymous requests per day per IP address, and its free plans require attribution. The default Boring Avatars URL points to a free community deployment. The official API is a paid service with its own domain, which you set with the
base_urloption. Thecolorsoption uses the free endpoint's format and is untested against the paid API.
Installation
This package requires PHP 8.2+ and Laravel 12 or 13. Laravel 11 is not supported because every 11.x release has an unpatched security advisory.
Laravel discovers the service provider and the Laravatar facade automatically.
Upgrading from v1
v1 stays available for Laravel 10. To stay on it, pin "martian/laravatar": "^1.0".
To upgrade, follow these steps:
-
Update the package:
-
Replace your published config file. The
classandoptionskeys are gone, and each driver's options now sit directly under its name.Copy your old values into the new file. The
LARAVATAR_DRIVERvalues are unchanged. The Boring Avatarssquaredoption is nowsquare. -
Update direct driver calls. The identifier now goes to
url(), and option methods drop thesetprefix. Each option method returns a new instance, so chain the calls or reassign the result.v1 v2 setSize(),setFormat(),setStyle(),setVariant()size(),format(),style(),variant()BoringAvatar::setSquared(),setColors('a,b')square(),colors(['a', 'b'])UiAvatars::setBackground(),setColor(),setRounded()background(),color(),rounded()new Laravatar($value)->getUrl()Laravatar::url($value)LaravatarFacadeAmplifiedHQ\Laravatar\Facades\Laravatar -
Update exception handling.
InvalidSizeException,InvalidFormatException,InvalidStyleException,InvalidVariantException,MissingPropertyException, andUnsupportedDriverExceptionare removed. CatchAmplifiedHQ\Laravatar\Exceptions\InvalidOptionExceptionfor bad options. An unknown driver throwsInvalidArgumentException. - Replace removed helpers. The
generate_color()andhex2rgba()global functions are removed.HasAvatar::generateAndSaveAvatar()is removed; usegetAvatarUrl().
[!IMPORTANT] v2 does not change avatar URLs already stored in your database. v1 stored DiceBear URLs that use API 7.x, which DiceBear shuts down on April 30, 2028. To regenerate them, run this once. It also replaces avatars your users uploaded, so narrow the query if you store those in the same column.
Configuration
Publish the configuration file:
Set the default driver in .env:
Each driver's options are listed in config/laravatar.php. Options that take a fixed set of values have an enum in AmplifiedHQ\Laravatar\Enums.
Usage
Using the HasAvatar trait
Add the trait to your model. When the model is created, it stores an avatar URL in the avatar column. It does not overwrite an avatar that was set explicitly, and it leaves the column empty when the source column is blank.
To fill avatars for existing rows, call getAvatarUrl():
[!IMPORTANT] Gravatar and Unavatar look up a real user, so use the email column with them. The other drivers accept any string column, such as
nameorusername.
Using the facade
Laravatar::url() uses the default driver. Laravatar::driver() selects another driver. Option methods return a new instance, so the configured driver is never changed.
You can also create a driver directly, for example (new Gravatar(size: 200))->url('[email protected]').
Invalid options throw AmplifiedHQ\Laravatar\Exceptions\InvalidOptionException.
Custom drivers
Implement AmplifiedHQ\Laravatar\Contracts\AvatarInterface and register the driver in a service provider:
Then set LARAVATAR_DRIVER=cdn, or call Laravatar::driver('cdn').
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Josiah Endurance
- AbdulHameed
- All Contributors
License
The MIT License (MIT). Please see License File for more information.