driesvints/blade-icons
Blade Icons lets you use SVG icons in Laravel Blade with simple components and directives. Convert files like camera.svg into or @svg('camera') with easy class/attribute control, and plug in community icon set packages.
Installation:
composer require blade-ui-kit/blade-icons
Publish the config (optional):
php artisan vendor:publish --provider="BladeUI\Icons\IconsServiceProvider"
First Use Case:
Register an icon set (e.g., Heroicons) in config/blade-icons.php:
'sets' => [
'heroicons' => [
'path' => 'vendor/driesvints/blade-icons/resources/svg/heroicons',
'prefix' => 'heroicon',
],
],
Use the directive in a Blade view:
@svg('heroicons/solid/camera', ['class' => 'w-6 h-6'])
Quick Start:
For a single icon, use the @svg directive:
@svg('camera', ['class' => 'w-6 h-6'])
Requires the camera.svg file in the default resources/svg directory.
Register Multiple Sets:
// config/blade-icons.php
'sets' => [
'heroicons' => ['path' => 'vendor/.../heroicons', 'prefix' => 'heroicon'],
'feather' => ['path' => 'vendor/.../feather', 'prefix' => 'feather'],
],
Use them in Blade:
@svg('heroicons/solid/camera')
@svg('feather/camera')
Custom Icon Sets:
Place SVGs in resources/svg/custom and register:
'custom' => ['path' => 'resources/svg/custom', 'prefix' => 'custom'],
Use:
@svg('custom/my-icon')
Generate Components:
php artisan vendor:publish --tag=blade-icons-components
This creates app/View/Components/Icons/ with pre-built components (e.g., Camera.php).
Use Components:
<x-icon-camera class="w-6 h-6" />
Customize via component class:
// app/View/Components/Icons/Camera.php
public function class($class)
{
return $this->withAttributes(['class' => $class]);
}
@svg('camera', ['class' => $dynamicClass, 'fill' => $color])
@svg($isActive ? 'check-circle' : 'x-circle')
List Available Icons:
php artisan icons:list
Outputs all registered icons with paths.
Search Icons:
php artisan icons:search camera
Missing SVG Files:
php artisan icons:list to verify.resources/svg/ for unregistered icons.Case Sensitivity:
@svg) and component names are case-sensitive.@svg('Camera') fails if the file is camera.svg.Caching Issues:
php artisan view:clear
Component Autoloading:
app/View/Components/Icons/ directory exists and is autoloaded. Run:
composer dump-autoload
Check Registered Sets:
// In a route or tinker
dd(config('blade-icons.sets'));
Verify SVG Paths:
Use php artisan icons:list to confirm paths. For custom sets, ensure the path in config/blade-icons.php is correct.
Directive Not Working:
Ensure the @svg directive is enabled in config/blade-icons.php:
'directive' => true,
Inline SVG vs. Components:
@svg for one-off icons; components (<x-icon-* />) for reusability and consistency.Optimize SVG Files:
Lazy-Loading:
Extending the Package:
@svg directive by publishing and modifying the BladeIconsServiceProvider.Icon class or using a custom resolver.Dynamic Icon Sets: Register sets dynamically in a service provider:
Icons::addSet('dynamic', [
'path' => storage_path('app/icons'),
'prefix' => 'dynamic',
]);
Icon Fallbacks: Provide fallback icons for missing SVGs:
@svg($iconName, ['class' => 'w-6 h-6', 'fallback' => 'x-circle'])
(Requires custom directive logic or a wrapper component.)
Icon Theming: Use CSS variables or inline styles to theme icons dynamically:
@svg('camera', [
'class' => 'text-primary',
'style' => "color: var(--icon-color)"
])
How can I help you explore Laravel packages today?