Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lavatar Laravel Package

vinicius73/lavatar

Lavatar is a Laravel package for generating avatar images from names or emails. It creates initials-based avatars with customizable colors, fonts, and sizes, caches generated images, and integrates easily with Eloquent models for simple user profile avatars.

View on GitHub
Deep Wiki
Context7

Getting Started

Reality check first. vinicius73/lavatar last shipped in July 2015, which puts it in the Laravel 4.2/5.0 era. On a modern app (Laravel 8+) composer require vinicius73/lavatar will almost certainly fail on illuminate/support, intervention/image, or PHP version constraints. Try it in a scratch branch first:

composer require vinicius73/lavatar --dry-run   # read the conflicts before committing

If you genuinely need it (legacy app, or you're evaluating for a migration), the path to a working install is:

  1. Install and publish config.

    composer require vinicius73/lavatar
    php artisan vendor:publish --provider="Vinicius73\Lavatar\LavatarServiceProvider"
    

    The provider namespace and config key (config/lavatar.php) are worth confirming directly in vendor/vinicius73/lavatar/src — the README is terse and the docs predate Laravel's package-discovery conventions.

  2. Read the source before the docs. With 24 stars and a 2015 release, src/ is the documentation. Look for the service provider (container bindings, config merge), the trait in src/Traits or similar, and the Blade helper/component registration. Ten minutes there saves an hour of guessing.

  3. Attach the trait to your User model.

    use Vinicius73\Lavatar\Traits\LavatarTrait;
    
    class User extends Authenticatable
    {
        use LavatarTrait;
    }
    
  4. First use case: the profile fallback. The canonical integration is "show uploaded photo, else generated initials." Wire it once in Blade and use it everywhere:

    <img src="{{ $user->profile_photo ?? lavatar($user->name) }}" alt="{{ $user->name }}">
    

    Confirm the helper's exact signature (name vs. model instance) in the source; adapt the call site, not the template.

Where to look first: config/lavatar.php for palette/size/font settings, then the Blade registration in the service provider. That tells you the public API surface in two files.

Implementation Patterns

Fallback chain in a single accessor. Don't scatter ?? logic through views. Wrap the package behind your own accessor so the template never knows which generator ran:

public function getAvatarUrlAttribute(): string
{
    return $this->profile_photo
        ?? ($this->hasGravatar() ? $this->gravatarUrl() : lavatar($this->name));
}

This is also your escape hatch — when you eventually replace Lavatar, only this method changes.

Gravatar-then-Lavatar. The package's stated niche. Check for a real Gravatar response (or just assume it, since Gravatar returns a default image) and fall through to initials. Cache the Gravatar probe per email so you're not doing an HTTP round-trip on every page render.

Precompute, don't render on request. Image generation is CPU-bound and involves disk I/O. Generate at account creation via a model observer, or a queued job, and persist the path:

User::created(fn ($user) => GenerateAvatar::dispatch($user));

Then the accessor reads a column, not a generator. This is the single biggest performance decision you'll make with this package.

Deterministic colour per user. Rather than a random palette pick (avatars change colour between requests — users notice), seed off a stable value:

$color = config('lavatar.palette')[$user->id % count(config('lavatar.palette'))];

If the package doesn't expose a per-call colour argument, subclass it or override the container binding.

Blade isolation. Wrap output in your own component (<x-avatar :user="$user" />) rather than calling the package helper in 40 templates. You get one place to add loading="lazy", alt escaping, and width/height attributes.

Config in version control. Publish config/lavatar.php and commit it. Font paths, output disk, and image dimensions belong in your repo, not in vendor defaults that shift under you.

Gotchas and Tips

  • The package is effectively abandoned. Pin an exact version in composer.json, or fork it into your org (repositories → vcs) and patch freely. Do not rely on upstream fixes; there won't be any.
  • Intervention Image version drift. Lavatar-era code targets Intervention Image 1.x/2.x; the current 3.x has a completely different API (ImageManager instead of the Image facade). A composer constraint conflict here is the most likely install blocker — resolve by pinning Intervention Image to the old major if nothing else in the app needs it.
  • GD + FreeType is mandatory. Without php-gd compiled with FreeType, text rendering silently degrades to empty or broken images. Verify with php -r "print_r(gd_info());" and check FreeType Support. Imagick is an alternative driver if the config exposes it.
  • Absolute font paths break on deploy. Docker images, Forge, and Vapor all have different filesystem layouts. Point the font config at base_path()/storage_path() or bundle the .ttf in your repo. A blank avatar in staging but not locally is usually this.
  • Multibyte initials. If the package uses substr() rather than mb_substr(), accented and CJK names produce mojibake or empty avatars. Test with José, Øyvind, and a CJK name. If it breaks, override the initials method rather than patching vendor.
  • Escape the alt attribute. Blade helpers that return raw <img> markup are an XSS vector if the name flows into an unescaped attribute. Use {{ }} around anything user-supplied, or return only the URL and build the tag yourself.
  • Disk and URL generation. If output goes to storage/app/public, you need php artisan storage:link. If you're behind a CDN or a non-standard ASSET_URL, asset() vs url() vs Storage::url() produce different results — pick one and verify it in production-shaped config.
  • Debugging a blank avatar. In order: (1) does config('lavatar') return merged values? (2) is the container binding resolving? (3) is the output directory writable by the web user? (4) can GD load the font? php artisan tinker with a single call isolates all four faster than log-reading.
  • Extension points. In order of preference: publish and edit config → override the container binding with your own subclass → fork the package. Avoid editing vendor/ directly; you'll lose it on the next composer install.
  • Migration advice. If you're starting fresh, laravolt/avatar is the maintained spiritual successor with the same concept, and a ~30-line SVG initials generator is genuinely competitive for this use case — no GD dependency, infinitely scalable, cache-friendly. Keep the $user->avatar_url accessor signature identical and the swap costs you an afternoon.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums