Laravel

oxblade-icons Alpha Rust

The laravel feature adds a service provider that builds the icon registry from application configuration, puts it in the container and registers the Blade extensions.

Install

[dependencies]
oxblade-icons = { version = "0.1", features = ["laravel"] }
oxblade-heroicons = { git = "https://github.com/bowerbird-si/oxblade-icon-sets" }

The feature is tested with laravel-rust 0.2 and oxblade-laravel 0.2.

Register the provider

Add IconsServiceProvider next to oxblade-laravel's BladeServiceProvider, with the sets you want:

use laravel::Application;
use oxblade_icons::{icon_set, laravel::IconsServiceProvider};
use oxblade_laravel::{BladeEngine, BladeServiceProvider};

let app = Application::configure()
    .with_providers(|providers| {
        providers.add(BladeServiceProvider::new(|_| BladeEngine::new()));
        providers.add(IconsServiceProvider::new().set(icon_set!(oxblade_heroicons)));
    })
    .create();

Views can then use svg(), @svg, <x-icon> and <x-heroicon-o-home /> (see Blade templates). No engine code is needed in the application. The registry is also in the container as Icons:

let icons = app.resolve::<oxblade_icons::Icons>().await;

Configure

IconsConfig holds the settings from Blade Icons' config/blade-icons.php. Set it in the application's configuration:

use oxblade_icons::{Attributes, laravel::{IconsConfig, SetConfig}};

let app = Application::configure()
    .with_config(|config, _| {
        config.set(IconsConfig {
            class: "icon".into(),
            attributes: Attributes::new().set("focusable", "false"),
            fallback: Some("heroicon-o-question-mark-circle".into()),
            sets: [("heroicons".into(), SetConfig {
                class: Some("size-6".into()),
                ..SetConfig::default()
            })]
            .into(),
            ..IconsConfig::default()
        });
    })
    // .with_providers(…) as above
    .create();
FieldBlade Icons keyMeaning
classclassClass for every icon
attributesattributesAttributes for every icon
fallbackfallbackFull icon name to show when one is missing
setssets.*.class, attributes, fallbackOverrides by set name; an empty fallback turns the set's fallback off
componentscomponentsblade::Options: which components to install

Without an IconsConfig, the provider reads ICONS_CLASS and ICONS_FALLBACK from the environment.

The configuration is checked when the application boots. A duplicate set or a fallback that doesn't exist makes boot() return the error, instead of failing on the first page.

Your own icons

To ship a folder of SVGs with the application, embed it with laravel::embed! and register it with oxblade_icons::laravel::embedded_set(name, prefix, folder). The files are trusted markup; see Icon sets.

Commands

  • icons:list lists the names in registered static sets.
  • icons:check lucide-map-pin heroicon-o-home checks exact names, even when a fallback is configured.
  • icons:licenses prints the notices for the sets the app registered.

Not included

Blade Icons' icons:cache and icons:clear commands have no equivalent: sets are compiled into the binary, so there is nothing to cache.