marispro/nova-vue-avatar
A lightweight Laravel Nova field for showing user avatars throughout your admin panel. Built with Vue, it renders profile images with graceful fallbacks so resource lists and detail views stay clean and consistent. Quick to install, simple to configure, and easy to style to match your Nova theme.
Install the package with Composer and, if the service provider is not auto-discovered, register it (Laravel 5.5+ auto-discovers). The core entry point is the Avatar facade/builder:
use Avatar;
$svg = Avatar::make('John Doe')->toSvg(); // check README for the exact terminal render method
Where to look first:
toSvg(), toHtml(), generate(), or similar) and the supported fluent options.php artisan vendor:publish --tag=avatar-config or per the README) for default shape, font, size, and color palette.Avatar::make(...) builder class itself — it is the main extension point and the fastest way to discover undocumented fluent methods.First use case: replace a Gravatar/placeholder fallback with a locally generated initials avatar on the user profile page:
<img src="{{ route('avatar', $user) }}" alt="{{ $user->name }}">
or inline the SVG directly to avoid an extra request:
{!! Avatar::make($user->name)->background('#4f46e5')->toSvg() !!}
Model accessor for a stable avatar URL. Wrap generation behind an accessor or dedicated AvatarService so controllers and views never call the facade directly:
public function getAvatarUrlAttribute(): string
{
return route('avatar.show', $this);
}
Deterministic color from a stable key. Rather than randomizing backgrounds, derive them from the user so the avatar is consistent across requests and caches:
$palette = ['#4f46e5', '#0ea5e9', '#10b981', '#f59e0b', '#ef4444'];
$color = $palette[crc32($user->email) % count($palette)];
Avatar::make($user->name)->background($color);
Cache the rendered SVG. SVG generation is cheap but not free; for list views (comments, team pages) cache per user and invalidate on name/color change:
$svg = Cache::remember("avatar:{$user->id}:{$user->updated_at}", now()->addDay(), fn () =>
Avatar::make($user->name)->background($user->avatar_color)->toSvg()
);
Serve via a controller route when you need HTTP caching, ETags, or to keep markup out of JSON payloads. Return response($svg)->header('Content-Type', 'image/svg+xml').
Store to disk for email/PDF contexts where inline SVG is not usable — render once on save (or in a queued job) and persist a PNG/SVG path on the model.
Blade component for consistency across views, with background defaulting from config and overridable per call site:
<x-avatar :name="$user->name" :background="$user->avatar_color ?? null" />
Release 0.6 integration: ->background('red') is additive and non-breaking. Adopt it where you previously post-processed SVG strings or wrapped avatars in a colored <div> — inline backgrounds are cleaner and survive export to files. Accepts named CSS colors; verify hex/rgb support against the README before relying on it.
'yellow', '#fde68a') with the default white/near-white initials is unreadable. Either pick a constrained palette or check whether the package exposes a foreground/text-color option alongside background().background() can receive request input, whitelist a palette or validate with a regex — an unvalidated value lands in an SVG fill attribute.{!! !!} if it does not escape by default."Ólafsdóttir", "李雷", and single-word names rather than assuming substr-style behavior.user_id will go stale when the name or background changes; include updated_at or a hash of the inputs in the key.<img> vs inline. External SVGs cannot load custom fonts unless embedded; if the font matters, inline the markup or convert to a path/PNG.^0.6 and run your avatar tests to confirm output is byte-identical for existing calls.How can I help you explore Laravel packages today?