composer require filafly/filament-icons
php artisan vendor:publish --provider="Filafly\FilamentIcons\FilamentIconsServiceProvider" --tag="filament-icons-config"
composer require filafly/filament-phosphor-icons
config/filament-icons.php:
'default' => 'phosphor',
Replace Filament’s Heroicons in a widget or page:
use Filafly\FilamentIcons\Facades\FilamentIcons;
FilamentIcons::set('heroicon-o-chart-bar', 'heroicon-o-chart-bar-solid'); // Override
FilamentIcons::set('heroicon-o-chart-bar', 'phosphor-chart-bar'); // Switch to Phosphor
Global Icon Overrides
Set defaults in config/filament-icons.php:
'aliases' => [
'heroicon-o-chart-bar' => 'phosphor-chart-bar',
],
Dynamic Icon Switching Use in Blade:
<x-dynamic-icon :name="$iconName" :style="$iconStyle" />
Or in PHP:
FilamentIcons::get('heroicon-o-chart-bar', 'solid');
Component-Level Overrides Extend a Filament component:
use Filafly\FilamentIcons\Concerns\HasFilamentIcons;
class MyWidget extends Widget implements HasFilamentIcons {
protected static string $icon = 'heroicon-o-chart-bar';
public function icon(): string {
return FilamentIcons::get($this->icon, 'solid');
}
}
Style Variations Pass styles dynamically:
FilamentIcons::get('phosphor-chart-bar', 'fill'); // Phosphor-specific style
FilamentIcons::get('heroicon-o-chart-bar', 'outline'); // Heroicon style
Blade Directives Register a directive for shorthand:
Blade::directive('icon', function ($name) {
return "<?php echo FilamentIcons::get($name); ?>";
});
Usage:
@icon('phosphor-chart-bar')
Resource Icons
Override resource icons in getHeaderActions() or getHeader():
public static function getHeaderActions(): array {
return [
FilamentIcons::get('heroicon-o-cog') => MyAction::make(),
];
}
Theme Switching Use middleware to change icon sets per theme:
public function handle(Request $request, Closure $next) {
FilamentIcons::setDriver('dark' === $request->theme ? 'phosphor-light' : 'phosphor');
return $next($request);
}
Style Mismatches
fill style may not align with Heroicon’s outline.FilamentIcons::mapStyle('outline', 'phosphor', 'regular');
Caching Headaches
php artisan view:clear.Missing Icons
FilamentIcons::alias('heroicon-o-chart-bar', 'phosphor-chart-bar');
Dependency Conflicts
@vite or @asset directives to scope CSS/JS.Log Icon Resolution Enable debug mode in config:
'debug' => env('FILAMENT_ICONS_DEBUG', false),
Check logs for resolved icons and styles.
Inspect Rendered HTML
Use browser dev tools to verify icon classes (e.g., i-phosphor-chart-bar).
Custom Drivers
Implement Filafly\FilamentIcons\Contracts\IconDriver:
class MyIconDriver implements IconDriver {
public function get($name, $style = null) {
return "my-icon-{$name}-{$style}";
}
}
Register via config:
'drivers' => [
'my-icons' => \App\Providers\MyIconDriver::class,
],
Dynamic Style Mapping Override style resolution:
FilamentIcons::mapStyle('outline', 'phosphor', 'bold');
Icon Fallbacks Set fallbacks for missing icons:
FilamentIcons::fallback('heroicon-o-chart-bar', 'heroicon-o-chart-bar-solid');
Icon Consistency
Use a IconRegistry trait to centralize icon definitions:
trait IconRegistry {
protected static array $icons = [
'dashboard' => 'phosphor-house',
'settings' => 'phosphor-gear',
];
}
Dark Mode Icons Leverage style variations for dark mode:
FilamentIcons::get('phosphor-moon', request()->darkMode ? 'fill' : 'regular');
Performance
Preload icon fonts in app.blade.php:
@if (FilamentIcons::hasDriver('phosphor'))
<link rel="preload" href="{{ asset('vendor/phosphor-icons/phosphor.css') }}" as="style">
@endif
How can I help you explore Laravel packages today?