mallardduck/blade-boxicons
Use Boxicons as Laravel Blade components. Drop in icons like , add classes or styles, and use regular, solid, and logo sets. Built on Blade Icons, with optional publishing of raw SVG assets.
Installation:
composer require mallardduck/blade-boxicons
Publish the config file (if needed):
php artisan vendor:publish --provider="MallardDuck\BladeBoxicons\BladeBoxiconsServiceProvider"
Basic Usage:
Add the service provider to config/app.php under providers:
MallardDuck\BladeBoxicons\BladeBoxiconsServiceProvider::class,
First Blade Usage:
@boxicon('bxl-github', '2x')
Renders a GitHub icon at 2x size.
Where to Look First:
config/blade-boxicons.php for customization options (e.g., CDN paths, default sizes).resources/views/vendor/blade-boxicons.blade.php (if published) for default templates.Dynamic Icons with Variables:
@boxicon($iconName, $size, ['class' => 'text-blue-500'])
Pass variables for icons, sizes, or additional attributes.
Icon Sets:
Use prefixes for different sets (e.g., bxl-, bx-, bxs-):
@boxicon('bxs-user', 'lg') <!-- Solid set -->
@boxicon('bx-user', 'sm') <!-- Regular set -->
Inline SVG Customization:
Override default SVG attributes via the attributes parameter:
@boxicon('bxl-laravel', 'md', [
'fill' => 'currentColor',
'aria-label' => 'Laravel'
])
Component Integration: Create reusable Blade components:
@component('components.icon', ['name' => 'bxl-react', 'size' => '1.5x'])
@endcomponent
Asset Optimization: Preload critical icons in your layout:
@boxicon('bxl-github', '1x', ['preload' => true])
@boxicon('bxl-python', 'md', ['class' => 'text-green-600 hover:scale-110'])
@boxicon('bxl-moon', 'sm', ['class' => 'dark:text-yellow-300'])
aria-hidden or labels for screen readers:
@boxicon('bxl-search', 'sm', ['aria-label' => 'Search'])
Icon Not Found:
@boxicon('invalid-icon', 'sm') <!-- Will output raw text if icon fails -->
storage/logs/laravel.log for missing icon warnings.CDN Dependencies:
config/blade-boxicons.php:
'cdn' => 'https://unpkg.com/boxicons@2.1.4',
'use_local_assets' => true,
Caching Issues:
php artisan view:clear
npm run prod
Size Limitations:
1x, 2x, 3x, 4x, 5x, 6x, 7x, 8x, 9x, 10x, sm, md, lg, xl.@dd() to debug the rendered SVG:
@boxicon('bxl-code', 'md', ['debug' => true])
config/blade-boxicons.php for typos or misconfigurations.Custom Icons:
Extend the package by adding a custom-icons config array:
'custom-icons' => [
'my-icon' => '<svg>...</svg>',
],
Usage:
@boxicon('my-icon')
Blade Directives: Override the default directive in your service provider:
Blade::directive('boxicon', function ($expression) {
// Custom logic here
return "<?php echo MallardDuck\BladeBoxicons\Facades\BladeBoxicons::render($expression); ?>";
});
Asset Pipelines: Integrate with Laravel Mix/Vite for bundling:
// vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { createBoxiconsPlugin } from 'vite-plugin-boxicons';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
}),
createBoxiconsPlugin(),
],
});
Testing: Mock the facade in PHPUnit:
$this->mock(BladeBoxicons::class)->shouldReceive('render')
->once()
->andReturn('<svg>Mock Icon</svg>');
How can I help you explore Laravel packages today?