Skip to content

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.

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);
}
}

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') !!}
@endif

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.svg

Download sets into the right place with --dest:

Terminal window
vendor/bin/swarm-icons json:download tabler heroicons mdi --dest=resources/json
  • Fluent API: all available methods on the Icon value object
  • Accessibility: decorative vs meaningful icons and ARIA best practices