owenvoke/blade-fontawesome
Easy Font Awesome integration for Laravel Blade. Provides Blade components/directives to render icons cleanly in views, supports different styles and sizes, and keeps markup consistent across your app without manual SVG or class boilerplate.
composer require owenvoke/blade-fontawesome
php artisan vendor:publish --tag=blade-fontawesome-config
<x-fas-cloud class="text-blue-500"/>
Replace outdated <i class="fas fa-user"></i> with:
<x-fas-user class="text-gray-600"/>
Why? Eliminates manual class management and leverages Blade’s component syntax for better IDE support.
<x-fas-home/>
<x-fas-home class="w-8 h-8 text-green-500 hover:text-green-700"/>
@icon('fas-' . $iconName, ['class' => 'text-blue-500'])
// config/blade-fontawesome.php
'sharp-solid' => false,
<img src="{{ asset('vendor/blade-fontawesome/solid/cloud.svg') }}" alt="Cloud"/>
php artisan blade-fontawesome:sync-icons --pro
php artisan blade-fontawesome:sync-icons --kit=YOUR_KIT_CODE
php artisan icons:cache
Use icons in dynamic components:
<button x-on:click="$wire.save()">
<x-fas-save class="mr-2"/>
Save
</button>
Combine with Tailwind classes for responsive icons:
<x-fas-search class="w-5 h-5 md:w-6 md:h-6 text-gray-400"/>
Extend the package to create domain-specific icons:
<!-- resources/views/components/icons/alert.blade.php -->
<x-fas-exclamation-triangle class="{{ $class ?? 'text-yellow-500' }}"/>
Usage:
<x-icons.alert class="text-red-500"/>
Register global icon helpers in AppServiceProvider:
use Owenvoke\BladeFontAwesome\Facades\BladeFontAwesome;
public function boot()
{
BladeFontAwesome::addDefaultClass('text-gray-600');
}
Icon Set Conflicts:
fas and sharp-solid simultaneously may cause duplicate icon definitions.config/blade-fontawesome.php:
'sharp-solid' => env('APP_ENV') !== 'production',
Pro/Kit Icons Not Loading:
--pro or --kit sync don’t appear.resources/icons/blade-fontawesome exists.storage/framework/cache/data for cached icons (clear with php artisan cache:clear).npm list @awesome.me/kit-*).Blade Caching Issues:
php artisan view:clear
PHP 8.3+ Compatibility:
CompileSvgsAction errors in newer PHP versions.v3.2.1+ or patch the service provider (see PR #107).List Available Icons:
php artisan blade-fontawesome:list
Outputs all registered icons (useful for troubleshooting missing icons).
Check Published Assets:
public/vendor/blade-fontawesome/:
php artisan vendor:publish --tag=blade-fontawesome --force
Log Icon Renders:
Add a temporary debug directive in AppServiceProvider:
Blade::directive('icondebug', function ($expression) {
\Log::debug("Rendering icon: $expression");
return "<?php echo '<!-- DEBUG: $expression -->'; ?>";
});
Usage:
@icondebug('fas-home')
Custom Icon Directives: Extend Blade directives for domain-specific icons:
// app/Providers/BladeServiceProvider.php
Blade::directive('usericon', function ($icon) {
return "<x-fas-user class=\"{$icon}\"/>";
});
Usage:
@usericon('text-blue-500')
Dynamic Icon Loading: Lazy-load icons based on user roles:
@if(auth()->user()->isAdmin())
<x-fas-user-shield/>
@else
<x-fas-user/>
@endif
Icon Variants: Create wrapper components for themed icons:
<!-- resources/views/components/icons/primary.blade.php -->
<x-fas-{{ $icon }} class="text-primary-500"/>
Usage:
<x-icons.primary icon="home"/>
Accessibility Enhancements: Add ARIA labels dynamically:
// app/Providers/BladeServiceProvider.php
Blade::component('fas-home', function ($component, $slot) {
$component->withAttributes(['aria-label' => 'Home']);
return $component;
});
Default Classes/Attributes:
Set global defaults in config/blade-fontawesome.php:
'default_classes' => 'text-gray-600',
'default_attributes' => ['role' => 'img'],
Self-Hosting Font Awesome: Disable CDN and use local assets:
'cdn' => false,
'local_path' => 'fonts/fontawesome',
Then publish assets:
php artisan vendor:publish --tag=blade-fontawesome --force
Icon Naming Conflicts:
Rename conflicting icons in config/blade-fontawesome.php:
'aliases' => [
'fas-home-alt' => 'fas-home',
],
Cache Pro/Kit Icons:
php artisan icons:cache
Reduces runtime icon resolution overhead.
Tree-Shake Unused Icons: If using Webpack/Vite, manually import only needed icons to reduce bundle size:
import { faUser, faHome } from '@fortawesome/free-solid-svg-icons';
Inline Critical Icons: For above-the-fold content, inline SVG directly in Blade:
{!! file_get_contents(public_path('vendor/blade-fontawesome/solid/home.svg')) !!}
How can I help you explore Laravel packages today?