orchid/blade-icons
Laravel package that adds Orchid icon set support to Blade Icons. Use Orchid icons as Blade components in your views, configure sets and prefixes, and render scalable SVG icons consistently across your app with the Blade Icons ecosystem.
Installation:
composer require orchid/blade-icons
Publish the config file (if needed):
php artisan vendor:publish --provider="Orchid\BladeIcons\BladeIconsServiceProvider" --tag="config"
Basic Usage:
Register an icon set (e.g., feather) in config/blade-icons.php:
'sets' => [
'feather' => [
'path' => 'vendor/orchid/blade-icons/src/sets/feather',
],
],
First Use Case: Render an icon in a Blade template:
<x-blade-icons.icon name="home" set="feather" />
Or use the helper:
{{ blade_icon('home', 'feather') }}
Dynamic Icon Rendering: Use Blade components or helpers to render icons dynamically based on conditions:
@if($user->isAdmin)
<x-blade-icons.icon name="users" set="feather" />
@else
<x-blade-icons.icon name="user" set="feather" />
@endif
Custom Icon Sets:
Add your own icon sets by extending the Orchid\BladeIcons\Sets\Set class and registering them in the config:
'custom' => [
'path' => 'app/BladeIcons/Sets/Custom',
],
Integration with Orchid Platform: If using Orchid Platform, leverage the built-in icon support:
<span class="icon">
<x-blade-icons.icon name="settings" set="feather" />
</span>
SVG Customization: Pass additional attributes to modify SVG output:
<x-blade-icons.icon name="edit" set="feather" class="text-red-500" width="24" />
Caching Icons: Pre-render icons in a view composer or service provider for performance:
BladeIcons::render('home', 'feather'); // Cache the rendered SVG
Icon Set Paths:
Ensure paths in config/blade-icons.php are correct. Use relative paths (e.g., vendor/orchid/blade-icons/src/sets/feather) for packaged sets and absolute paths (e.g., app/BladeIcons/Sets/Custom) for custom sets.
Namespace Conflicts:
Avoid naming custom icon sets or files to conflict with existing sets (e.g., don’t name a custom set feather).
SVG Security: Sanitize dynamic icon names to prevent SVG injection attacks:
$safeName = htmlspecialchars($request->input('icon_name'));
Caching Issues: Clear Blade cache if icons fail to render after updates:
php artisan view:clear
Check Registered Sets: Dump registered sets to verify configuration:
dd(config('blade-icons.sets'));
Verify Icon Existence:
Ensure the icon file exists in the specified set directory (e.g., vendor/orchid/blade-icons/src/sets/feather/home.svg).
Debug SVG Output:
Use {{ blade_icon('home', 'feather', true) }} to output raw SVG for inspection.
Custom SVG Processing:
Extend the Orchid\BladeIcons\BladeIcons facade to modify SVG output:
BladeIcons::extend(function ($svg) {
return str_replace('<svg', '<svg data-custom="attribute"', $svg);
});
Icon Aliases: Create aliases for frequently used icons in a service provider:
BladeIcons::alias('home', 'feather/home');
// Usage:
<x-blade-icons.icon name="home" />
Dynamic Set Loading: Load icon sets dynamically based on user roles or environments:
if (app()->environment('production')) {
config(['blade-icons.sets.production' => [...]]);
}
How can I help you explore Laravel packages today?