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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravatar

Laravatar

Latest Version on Packagist Total Downloads GitHub Actions

🚀 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 Email
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_url option. The colors option 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:

  1. Update the package:

  2. Replace your published config file. The class and options keys are gone, and each driver's options now sit directly under its name.

    Copy your old values into the new file. The LARAVATAR_DRIVER values are unchanged. The Boring Avatars squared option is now square.

  3. Update direct driver calls. The identifier now goes to url(), and option methods drop the set prefix. 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)
    LaravatarFacade AmplifiedHQ\Laravatar\Facades\Laravatar
  4. Update exception handling. InvalidSizeException, InvalidFormatException, InvalidStyleException, InvalidVariantException, MissingPropertyException, and UnsupportedDriverException are removed. Catch AmplifiedHQ\Laravatar\Exceptions\InvalidOptionException for bad options. An unknown driver throws InvalidArgumentException.

  5. Replace removed helpers. The generate_color() and hex2rgba() global functions are removed. HasAvatar::generateAndSaveAvatar() is removed; use getAvatarUrl().

[!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 name or username.

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

License

The MIT License (MIT). Please see License File for more information.


All versions of laravatar with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package martian/laravatar contains the following files

Loading the files please wait ...