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();| Field | Blade Icons key | Meaning |
|---|---|---|
class | class | Class for every icon |
attributes | attributes | Attributes for every icon |
fallback | fallback | Full icon name to show when one is missing |
sets | sets.*.class, attributes, fallback | Overrides by set name; an empty fallback turns the set's fallback off |
components | components | blade::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:listlists the names in registered static sets.icons:check lucide-map-pin heroicon-o-homechecks exact names, even when a fallback is configured.icons:licensesprints 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.