codeat3/blade-phosphor-icons
Use Phosphor Icons in Laravel Blade via simple <x-phosphor-*> components. Built on Blade Icons with support for caching and configurable defaults. Requires PHP 7.4+ and Laravel 8+. Includes v1/v2 Phosphor icon sets and easy upgrades.
Installation:
composer require codeat3/blade-phosphor-icons
Publish the config (optional):
php artisan vendor:publish --provider="Codeat3\BladePhosphorIcons\BladePhosphorIconsServiceProvider" --tag="config"
First Use Case: Add the directive to your Blade view:
@phosphor("heroicons-outline:home")
Or use the helper:
{!! phosphorIcon('heroicons-outline:home') !!}
Where to Look First:
config/blade-phosphor-icons.php (for customization)resources/views/vendor/blade-phosphor-icons/ (default templates)Dynamic Icons:
@php
$icon = request()->routeIs('dashboard') ? 'heroicons-outline:home' : 'heroicons-outline:dashboard';
@endphp
@phosphor($icon)
Reusable Components:
Create a Blade component (resources/views/components/icon.blade.php):
<x-icon :name="$name" :size="$size" :color="$color" />
Usage:
<x-icon name="heroicons-outline:user" size="24" color="blue-500" />
Integration with Tailwind CSS:
@phosphor("heroicons-outline:bell", [
'class' => 'text-blue-500 hover:text-blue-700',
'aria-hidden' => 'true'
])
Conditional Rendering:
@if(auth()->check())
@phosphor("heroicons-outline:user-circle")
@else
@phosphor("heroicons-outline:user")
@endif
Loop Through Icons:
@foreach(['home', 'dashboard', 'settings'] as $route)
@phosphor("heroicons-outline:{$route}")
@endforeach
Laravel 13 Compatibility:
The package now officially supports Laravel 13. Ensure your composer.json and dependencies are updated:
"require": {
"laravel/framework": "^13.0"
}
<button x-on:click="toggle" @phosphor("heroicons-outline:toggle-left") />
<button type="submit" @phosphor("heroicons-outline:paper-airplane")>
Submit
</button>
Icon Not Found:
heroicons-outline:home).heroicons-outline, heroicons-solid).'icon_sets' => [
'heroicons-outline' => resource_path('icons/heroicons-outline.svg'),
],
Caching Issues:
php artisan view:clear
npm run dev
php artisan config:cache
php artisan route:cache
SVG Injection Risks:
$safeIcon = preg_replace('/[^a-zA-Z0-9:_-]/', '', $userInput);
@phosphor($safeIcon)
@dump(\Codeat3\BladePhosphorIcons\Facades\PhosphorIcons::availableIcons())
Custom Icon Sets:
Add your own SVG files to resources/icons/ and update the config:
'icon_sets' => [
'custom' => resource_path('icons/custom.svg'),
],
Usage:
@phosphor("custom:my-icon")
Size and Color: Pass attributes directly:
@phosphor("heroicons-outline:star", [
'width' => '20',
'height' => '20',
'fill' => 'currentColor',
'style' => 'color: red'
])
Dark Mode Support: Use Tailwind’s dark mode classes with the icon:
@phosphor("heroicons-outline:moon", [
'class' => 'dark:text-yellow-300'
])
Performance:
@phosphor("heroicons-outline:home", ['class' => 'hidden'])
inline option to embed SVGs directly (avoids extra HTTP requests):
@phosphor("heroicons-outline:home", ['inline' => true])
php artisan optimize:clear
Testing: Test icon rendering in PHPUnit:
$this->blade()->render('@phosphor("heroicons-outline:home")')
->assertSee('<svg');
Laravel 13 Migration:
AppServiceProvider is updated to use Laravel 13's boot method signature:
public function boot(): void
{
// Your boot logic
}
config/app.php includes the correct service provider registration.How can I help you explore Laravel packages today?