blade-ui-kit/blade-icons
Use SVG icons in Laravel Blade with simple components and directives. Turn SVG files into or @svg('name') calls, support multiple icon sets/packages, and customize classes/attributes for consistent, reusable icons across your app.
composer require blade-ui-kit/blade-icons
heroicons):
php artisan vendor:publish --tag=blade-icons
resources/svg). For example:
resources/svg/heroicons/solid/camera.svg
<x-icon-camera class="w-6 h-6" />
Or via the @svg directive:
@svg('heroicons.solid.camera', 'w-6 h-6')
Replace this:
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-6 h-6">
<!-- SVG path data -->
</svg>
With this:
<x-icon-camera class="w-6 h-6" />
config/blade-icons.php:
'default' => 'heroicons',
@iconSet('feather')
<x-icon-user class="w-6 h-6" />
camera.svg → <x-icon-camera />).app/Providers/BladeIconsServiceProvider.php:
BladeIcons::register('camera', 'custom-camera');
@svg('heroicons.solid.camera', ['class' => 'w-6 h-6'])
@svg('heroicons.solid.camera', ['class' => 'w-6 h-6', 'aria-label' => 'Camera'])
{!! svg('heroicons.solid.camera', ['class' => 'w-6 h-6']) !!}
@component('components.icon', ['name' => 'heroicons.solid.camera', 'classes' => 'w-6 h-6'])
@endcomponent
<x-icon name="heroicons.solid.camera" class="w-6 h-6" />
<x-icon-camera class="text-blue-500 dark:text-blue-400" />
@svg directive:
@svg('heroicons.solid.camera', ['style' => 'color: red;'])
<div x-data="{ showIcon: false }">
<button @click="showIcon = true">Load Icon</button>
<x-icon-camera x-show="showIcon" class="w-6 h-6" />
</div>
// In a middleware or service provider
config(['blade-icons.default' => Auth::user()->preferred_icon_set]);
Missing SVG Files:
Class 'App\View\Components\IconCamera' not found.resources/svg/heroicons/solid/camera.svg).php artisan blade-icons:list to verify registered icons.Caching Issues:
php artisan view:clear
php artisan blade-icons:clear-cache (if available in newer versions).Namespace Conflicts:
Class 'IconCamera' conflicts with another component.<x-icons::heroicons::solid::camera />
SVG ViewBox or Fill Attributes:
viewBox or fill attributes.@svg directive to override attributes:
@svg('heroicons.solid.camera', ['fill' => 'currentColor', 'viewBox' => '0 0 24 24'])
Case Sensitivity:
Camera vs. camera).camera.svg) and use kebab-case in Blade:
<x-icon-camera /> <!-- Not <x-iconCamera /> -->
List Registered Icons:
php artisan blade-icons:list
Outputs all available icons and their paths.
Inspect SVG Content:
Use the @svg directive to dump raw SVG content:
@dump(svg('heroicons.solid.camera'))
Check Config:
Verify the config/blade-icons.php file for correct paths and icon sets.
Custom Icon Sets:
'sets' => [
'heroicons' => resource_path('svg/heroicons'),
'custom' => resource_path('svg/custom-icons'),
],
BladeIcons::add('custom', resource_path('svg/custom-icons'));
Modify SVG Output:
@svg directive with custom attributes:
@svg('heroicons.solid.camera', [
'class' => 'w-6 h-6',
'xmlns' => 'http://www.w3.org/2000/svg',
'role' => 'img',
])
BladeIconsServiceProvider to modify SVG tags:
BladeIcons::macro('modifySvg', function ($svg, $name) {
return str_replace('<svg', '<svg role="img"', $svg);
});
Icon Aliases:
BladeIcons::alias('user', 'heroicons.solid.user');
Now use:
<x-icon-user /> <!-- Instead of <x-icon-heroicons-solid-user /> -->
Icon Sets from External Sources:
BladeIcons::addRemote('remote-icons', 'https://example.com/icons/', function ($name) {
return file_get_contents("https://example.com/icons/{$name}.svg");
});
BladeIcons::cacheSvg(true);
BladeIcons::loadSet('heroicons');
BladeIcons::loadSet('feather');
public function test_icon_rendering()
{
$this->blade->render('<x-icon-camera />')
->assertSee('<svg');
}
public function test_svg_content()
{
$svg = svg('heroicons.solid.camera');
$this->assertStringContainsString('viewBox="0 0 24 24"', $svg);
}
Extend the @svg directive in the service provider:
Blade::directive('icon', function ($expression) {
return "<?php echo blade_icons_svg({$expression}); ?>";
});
Now use:
@icon('heroicons.solid.camera', ['class' =>
How can I help you explore Laravel packages today?