Laravel Blade
Swarm Icons works in Laravel out of the box (no extra package needed). Register the manager once in a service provider, and the swarm_icon() helper is available in every Blade template.
Register the manager
Section titled “Register the manager”Add this to your AppServiceProvider:
use Frostybee\SwarmIcons\SwarmIcons;use Frostybee\SwarmIcons\SwarmIconsConfig;
class AppServiceProvider extends ServiceProvider{ public function register(): void { $manager = SwarmIconsConfig::create() ->discoverJsonSets(resource_path('json')) ->cachePath(storage_path('framework/cache/icons')) ->defaultPrefix('tabler') ->defaultAttributes(['class' => 'icon']) ->build();
SwarmIcons::setManager($manager); }}Use icons in Blade
Section titled “Use icons in Blade”Since swarm_icon() returns raw SVG, you need unescaped output:
{!! swarm_icon('home') !!}{!! swarm_icon('heroicons:check', ['class' => 'w-6 h-6']) !!}{!! swarm_icon('tabler:star', ['aria-label' => 'Favorite']) !!}You can chain fluent methods inline:
{!! swarm_icon('home')->size(24)->class('text-blue-500') !!}{!! swarm_icon('tabler:star')->fill('currentColor')->strokeWidth(1.5) !!}And check for existence before rendering:
@if(SwarmIcons::has('heroicons:user')) {!! swarm_icon('heroicons:user') !!}@endifWhere to put your icons
Section titled “Where to put your icons”A typical Laravel project might organize icon files like this:
resources/├── json/ ← downloaded JSON collections│ ├── tabler.json│ ├── heroicons.json│ └── mdi.json└── icons/ ← custom SVG icons (if any) ├── logo.svg └── brand.svgDownload sets into the right place with --dest:
vendor/bin/swarm-icons json:download tabler heroicons mdi --dest=resources/jsonSee also
Section titled “See also”- Fluent API: all available methods on the
Iconvalue object - Accessibility: decorative vs meaningful icons and ARIA best practices