voltra/filament-svg-avatar
Swap Filament’s default avatar URL provider for inline SVG avatars. Generate initials-based avatars without external HTTP requests, with configurable size, background/text colors, and font family. Includes publishable config and optional view overrides.
composer require voltra/filament-svg-avatar
php artisan vendor:publish --tag="filament-svg-avatar-config"
PanelProvider:
use Voltra\FilamentSvgAvatar\FilamentSvgAvatarPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FilamentSvgAvatarPlugin::make()
->backgroundColor(Hex::fromString('#3b5998'))
->textColor(Hex::fromString('#e9ebee')),
]);
}
Replace default Gravatar/URL-based avatars with inline SVG avatars (no external HTTP requests). Ideal for:
Use the plugin for global SVG avatar replacement with minimal setup:
FilamentSvgAvatarPlugin::make()
->backgroundColor('#2563eb') // Hex or Spatie\Color\Hex
->textColor('#ffffff')
->svgSize(600) // Optional: Override global config
->disallowPluginOverride(true); // Prevent further overrides
Pros:
config/filament-svg-avatar.php.For fine-grained control, replace the default provider:
->defaultAvatarProvider(
\Voltra\FilamentSvgAvatar\Filament\AvatarProviders\RawSvgAvatarProvider::class
)
Use case: When you need to extend the SvgAvatarService logic (e.g., dynamic initials logic).
Replace Filament’s <x-filament::avatar/> with an SVG version:
php artisan vendor:publish --tag=filament-svg-avatar-core-overrides
Key files:
resources/views/vendor/filament/components/avatar.blade.phpresources/views/vendor/filament-svg-avatar/avatar-override.blade.phpWhen to use:
viewBox, aria-label).Override defaults per-panel or per-resource:
// In a service provider:
$this->app->scoped(
\Voltra\FilamentSvgAvatar\Contracts\SvgAvatarServiceContract::class,
MyCustomSvgAvatarService::class
);
Example: Dynamic colors based on user roles:
class MyCustomSvgAvatarService extends FilamentSvgAvatarService
{
public function getBackgroundColor(string $initials): string
{
return $initials === 'ADMIN' ? '#ef4444' : parent::getBackgroundColor($initials);
}
}
Font Availability:
RawSvgAvatarProvider + publish the override template to ensure custom fonts work.Plugin vs. Provider Order:
->plugins([FilamentSvgAvatarPlugin::make()])
->defaultAvatarProvider(MyCustomProvider::class) // Must come last!
Config Precedence:
config/filament-svg-avatar.php > Service overrides.disallowPluginOverride(true) to lock global settings.Alt Attribute Bleeding:
alt to SVGs (invalid). v1.2.5+ fixes this automatically.<svg ...> <!-- Should NOT have `src` or `alt` -->
<text x="50%" y="50%" dy=".3em">JD</text>
</svg>
getInitials() in your SvgAvatarService to use:
public function getInitials(string $name): string
{
return Str::of($name)->take(2)->upper()->value();
}
svgSize config or override the getSize() method in your service.avatar-override.blade.php to add:
<svg ... style="filter: drop-shadow(0 0 2px rgba(0,0,0,0.3))">
filament.php under cache).svgSize to a reasonable value (e.g., 500) to avoid bloated markup.php artisan vendor:publish --tag=filament-svg-avatar-core-overrides --force
php artisan view:clear
How can I help you explore Laravel packages today?