davidhsianturi/blade-bootstrap-icons
Laravel package that brings Bootstrap Icons to Blade. Use simple Blade components to render SVG icons with customizable size, class, and other attributes. Quick to install, lightweight, and ideal for consistent icon usage across your app.
Installation
composer require davidhsianturi/blade-bootstrap-icons
No publisher or service provider needed—just use the Blade directive immediately.
First Usage Add the directive to your Blade template:
@bootstrapIcons
Now you can use icons like this:
<i class="bi bi-heart"></i>
Where to Look First
resources/views for existing Blade templates to see how icons are integrated.Direct Icon Usage Embed icons inline in Blade:
<button>
<i class="bi bi-check-circle-fill"></i> Confirm
</button>
Dynamic Icons via Variables Use Blade variables to switch icons dynamically:
<i class="bi bi-{{ $status === 'active' ? 'check' : 'x' }}"></i>
Component-Based Icons Create reusable Blade components:
@component('icons.button', ['icon' => 'bi-bell'])
Notifications
@endcomponent
Integration with Tailwind CSS Combine with Tailwind for styling:
<i class="bi bi-arrow-right text-blue-500"></i>
Lazy-Loading Icons Load icons only when needed (e.g., in AJAX responses):
@if($showIcon)
@bootstrapIcons
<i class="bi bi-search"></i>
@endif
app.blade.php).
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<i class="fas fa-star"></i> <!-- Font Awesome -->
<i class="bi bi-star"></i> <!-- Bootstrap Icons -->
.bi { color: var(--bs-icon-color); }
Missing CSS/JS
bootstrap-icons.css.Icon Naming Conflicts
bi-arrow-up) may conflict with custom CSS classes.<i class="bootstrap-icons bi bi-arrow-up"></i>
Caching Issues
php artisan view:clear
php artisan cache:clear
Version Mismatch
composer.json and CDN links. Example:
<!-- Use version 1.11.3 if package targets it -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
class attribute includes bi and the correct icon name (e.g., bi bi-heart).Failed to load resource for missing CSS/JS.<i class="bi bi-heart @error('icon') text-danger @enderror"></i>
Custom Icon Sets Extend the package by adding your own icons to the Blade directive. Example:
@inject('icons', 'Davidhsianturi\BladeBootstrapIcons\BootstrapIconsServiceProvider')
@php $icons->addCustomIcon('bi-custom', 'path/to/custom-icon.svg'); @endphp
(Note: Requires modifying the package or creating a wrapper.)
Dynamic Icon Loading Load icons conditionally based on user roles or settings:
@if(auth()->user()->can('admin'))
@bootstrapIcons
<i class="bi bi-gear"></i>
@endif
Icon Size Utilities Combine with Laravel Mix/PurgeCSS to generate utility classes for icon sizing:
/* resources/css/app.css */
.icon-sm { font-size: 0.75rem; }
.icon-lg { font-size: 1.5rem; }
Usage:
<i class="bi bi-heart icon-lg"></i>
Local Development
For local testing, link the Bootstrap Icons CSS directly from node_modules:
<link rel="stylesheet" href="{{ asset('node_modules/bootstrap-icons/font/bootstrap-icons.css') }}">
How can I help you explore Laravel packages today?