themesberg/flowbite-blade-icons
Use Flowbite Icons in Laravel Blade via easy SVG components and the @svg directive. Supports outline and solid sets, classes and attributes, optional config publishing, and Blade Icons features like caching. Requires PHP 8.1+ and Laravel 9+.
Install the package:
composer require themesberg/flowbite-blade-icons
Use an icon in a Blade view:
<x-fwb-o-adjustments-horizontal class="w-6 h-6 text-gray-500" />
fwb-o-adjustments-horizontal with any Flowbite icon.fwb-s-* prefix (e.g., <x-fwb-s-adjustments-horizontal />).Verify the icon renders in your view. No additional configuration is required for basic usage.
<nav class="flex space-x-4">
<x-fwb-o-home class="w-5 h-5" />
<x-fwb-o-settings class="w-5 h-5" />
<x-fwb-o-user class="w-5 h-5" />
</nav>
Result: A navigation bar with three icons, styled via Tailwind classes.
Use Blade components for type-safe, IDE-friendly icon references:
<!-- Outline icon -->
<x-fwb-o-cart class="text-red-500 hover:text-red-700" />
<!-- Solid icon -->
<x-fwb-s-star class="text-yellow-400" />
<!-- With dynamic classes -->
<x-fwb-o-bell class="{{ request()->has('notifications') ? 'text-blue-500 pulse' : 'text-gray-400' }}" />
Group related icons (e.g., a dashboard toolbar):
<div class="flex space-x-2">
@foreach(['home', 'settings', 'notifications', 'user'] as $icon)
<x-fwb-o-{{ $icon }} class="w-5 h-5 text-gray-600 hover:text-gray-900" />
@endforeach
</div>
Use the @svg directive when icons are determined at runtime:
@svg(
$name = $user->role === 'admin' ? 'fwb-s-shield-check' : 'fwb-o-user',
$classes = 'w-6 h-6',
$attributes = ['aria-label' => $user->role]
)
@svg(
$name = config('app.icon.' . $feature->type) ?? 'fwb-o-question-mark',
$classes = 'w-5 h-5 text-gray-500'
)
Publish the config to set default classes/attributes for all icons:
php artisan vendor:publish --tag=flowbite-blade-icons-config
Edit config/flowbite-blade-icons.php:
'default_classes' => 'w-5 h-5 text-gray-500',
'default_attributes' => ['aria-hidden' => 'true'],
Result: All icons inherit these defaults unless overridden:
<x-fwb-o-home /> <!-- Uses w-5 h-5 text-gray-500 aria-hidden="true" -->
<x-fwb-o-settings class="text-blue-500" /> <!-- Overrides text color -->
Publish SVG files for use in non-Blade contexts (e.g., JavaScript, CSS):
php artisan vendor:publish --tag=flowbite-blade-icons --force
Use in views:
<img src="{{ asset('vendor/flowbite-blade-icons/o-adjustments-horizontal.svg') }}" alt="Settings" width="20" height="20" />
Combine SVGs into a sprite sheet for reduced HTTP requests:
# Use a tool like `svgsprite` to process published SVGs
svgsprite --input resources/svg --output public/sprite.svg
Reference in HTML:
<svg class="w-6 h-6">
<use href="{{ asset('sprite.svg#o-adjustments-horizontal') }}" />
</svg>
Pair icons with Flowbite’s UI components (e.g., buttons, dropdowns):
<button class="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded">
<x-fwb-o-settings class="w-5 h-5" />
Settings
</button>
<x-dropdown>
<x-slot name="trigger">
<button class="flex items-center gap-1">
<x-fwb-o-cog />
<span>Configure</span>
</button>
</x-slot>
<!-- Dropdown items -->
</x-dropdown>
Enable Blade Icons caching to reduce view compilation time:
php artisan cache:clear
Configure in config/blade-icons.php (published by blade-ui-kit/blade-icons):
'cache' => [
'enabled' => true,
'path' => storage_path('framework/cache/blade-icons'),
],
Icon Naming Confusion
fwb-o-* (outline) and fwb-s-* (solid) prefixes.Caching Issues
php artisan view:clear
php artisan cache:clear
'cache' => ['enabled' => false] in blade-icons.php).SVG currentColor Quirks
fill="currentColor" is missing (pre-v1.2.1).composer update themesberg/flowbite-blade-icons
style="color: red" to verify inheritance:
<x-fwb-o-home style="color: red" />
Config Publishing Overwrite
vendor:publish multiple times overwrites config/flowbite-blade-icons.php.--force carefully.IDE Autocomplete Limitations
.editorconfig:
[*.blade.php]
blade_component_autocomplete = true
Inspect Rendered SVG Use browser dev tools to verify the compiled SVG:
<x-fwb-o-home class="w-6 h-6" style="outline: 1px solid red" />
Check for Typos
Component class [fwb-o-home] does not exist.Disable Caching Temporarily
Set 'cache' => ['enabled' => false] in blade-icons.php to test changes without clearing cache.
Validate SVG Output Ensure SVGs render correctly in isolation:
@svg('fwb-o-home', 'w-0 h-0', ['style' => 'display: none'])
composer remove themesberg/flowbite-blade-icons && composer require themesberg/flowbite-blade-icons
Custom Icon Sets
resources/svg).php artisan vendor:publish --tag=flowbite-blade-icons --force
resources/svg/custom/.BladeIcons::register('fwb-c-*', resource_path('svg/custom'));
Dynamic Icon Resolution
How can I help you explore Laravel packages today?