blade-ui-kit/blade-icons
Use SVG icons in Laravel Blade with simple components and directives. Convert SVG files into <x-icon-... /> tags or @svg() calls, add classes/attributes easily, and plug in many third‑party icon set packages for quick, consistent icons across your app.
Installation:
composer require blade-ui-kit/blade-icons
php artisan vendor:publish --tag=blade-icons
Uncomment the default icon set in config/blade-icons.php (e.g., heroicons or feather).
Place Icons:
Copy SVG files (e.g., camera.svg) into resources/svg/[icon-set-name] (e.g., resources/svg/heroicons/solid).
First Use Case: Render an icon in Blade:
<x-icon-camera class="w-6 h-6" />
Or use the @svg directive:
@svg('camera', 'w-6 h-6')
Verify: Check the icon search tool for available icons in your chosen set.
Icon Rendering:
<x-icon-[name] /> (e.g., <x-icon-user />).
<x-icon-user class="text-blue-500" />
@svg('icon-name', 'classes').
@svg('user', 'text-blue-500 w-8')
@svg($iconName, 'w-6 h-6')
Icon Sets:
config/blade-icons.php:
'sets' => [
'heroicons' => [
'path' => resource_path('svg/heroicons'),
'prefix' => 'heroicon',
],
'feather' => [
'path' => resource_path('svg/feather'),
'prefix' => 'feather',
],
],
icon helper to specify a set:
@svg('user', 'w-6 h-6', 'feather')
Customization:
<x-icon-camera fill="red" />
@svg('camera', 'w-6 h-6', [], ['fill' => 'red'])
// app/View/Composers/IconComposer.php
public function compose($view) {
$view->with('icons', ['user', 'camera']);
}
@foreach($icons as $icon)
<x-icon-{{ $icon }} />
@endforeach
Dynamic Icon Loading:
@auth
<x-icon-user />
@endauth
Integration with UI Components:
<button>
<x-icon-settings class="mr-2" />
Settings
</button>
Icon Packs:
blade-heroicons) for extended icon libraries:
composer require blade-ui-kit/blade-heroicons
config/blade-icons.php:
'sets' => [
'heroicons' => [
'path' => resource_path('vendor/blade-ui-kit/blade-heroicons/resources/svg'),
'prefix' => 'heroicon',
],
],
Missing SVG Files:
Icon [name] not found.resources/svg/[set-name]/[icon].svg). Use php artisan svg-discover to auto-discover icons (if available in newer versions).Caching Issues:
php artisan view:clear
php artisan config:clear
Case Sensitivity:
camera.svg not Camera.svg).Namespace Conflicts:
<x-myapp-icon-camera />
Large Icon Sets:
Verify Icon Paths:
config/blade-icons.php for correct path and prefix values. Example:
'heroicons' => [
'path' => resource_path('svg/heroicons/solid'),
'prefix' => 'heroicon-solid',
],
Inspect SVG Output:
viewBox or fill attributes.Log Missing Icons:
@php
if (!Icon::exists('unknown-icon')) {
\Log::warning('Icon not found: unknown-icon');
}
@endphp
Custom SVG Handling:
php artisan vendor:publish --tag=blade-icons-views
resources/views/vendor/blade-icons/icon.blade.php.Custom Icon Sets:
config/blade-icons.php:
'custom-set' => [
'path' => resource_path('svg/custom'),
'prefix' => 'custom',
],
@svg directive with the custom set:
@svg('my-icon', 'w-6 h-6', 'custom')
Dynamic Icon Generation:
// app/Helpers/IconHelper.php
public static function getDynamicIcon($type) {
$svg = Icon::get("{$type}-icon");
return str_replace('currentColor', '#4A5568', $svg);
}
{!! IconHelper::getDynamicIcon('user') !!}
Icon Animation:
<x-icon-spinner class="animate-spin" />
@keyframes spin {
to { transform: rotate(360deg); }
}
.animate-spin {
animation: spin 1s linear infinite;
}
Accessibility:
<x-icon-search aria-label="Search" />
aria-hidden attribute for decorative icons:
<x-icon-logo aria-hidden="true" />
Dark Mode Support:
<x-icon-moon class="dark:text-yellow-300" />
.dark .icon-dark { filter: invert(1); }
Icon Optimization:
Default Set:
default set in config/blade-icons.php to avoid runtime errors:
'default' => 'heroicons',
Prefix Handling:
prefix: 'heroicon' → <x-icon-heroicon-user />prefix: 'feather' → <x-icon-feather-user />Path Validation:
mkdir -p resources/svg/heroicons/solid
Environment-Specific Configs:
'sets' => env('ICON_SET') === 'production'
? ['heroicons' => [...]]
: ['feather' => [...]],
How can I help you explore Laravel packages today?