Download the PHP package teksite/icon-laravel without Composer
On this page you can find all versions of the php package teksite/icon-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download teksite/icon-laravel
More information about teksite/icon-laravel
Files in teksite/icon-laravel
Package icon-laravel
Short Description This package is a simple and tiny SVG icons font laravel
License MIT
Informations about the package icon-laravel
Teksite Icon Laravel
A simple, lightweight Laravel package for using SVG icons directly in Blade components.
Requirements
- PHP 8.3+
- Laravel 13+
Installation
Install the package with Composer:
The service provider is automatically discovered by Laravel.
Publishing Assets
Publish the package configuration:
Publish the icon assets:
You can also publish each asset group separately:
The published files are placed under:
The configuration file is:
Configuration
The default configuration looks like this:
Icon Sources
The package supports multiple icon types.
By default:
Custom icon JSON files take priority when they exist.
If a configured file does not exist, the package automatically falls back to the package's bundled resource:
For example:
You can define additional custom icon types by adding them to the configuration:
The icon type must contain only letters, numbers, underscores, or hyphens.
Using Icons
The package provides two Blade components:
and:
Both components use the same icon manager and support the same main properties.
Basic Usage
or:
The default icon type is:
To use a solid icon:
Component Attributes
The component supports the following properties:
Example:
Additional HTML attributes can also be passed to the component:
The component merges the provided class with its default classes.
Generated SVG
The component renders an SVG element similar to:
Custom Component View
The default component view is configured as:
You can change it in:
For example:
The configured view receives:
The icon component also exposes its normal Blade component properties and attributes.
If the configured view does not exist, the Icon component logs an error and falls back to an inline SVG renderer.
Difference Between icon and tkicon
Both components provide the same basic functionality.
<x-icon>
<x-icon> supports a configurable Blade view through:
If the configured view exists, it is used for rendering.
If it does not exist, the component uses its built-in fallback renderer.
<x-tkicon>
<x-tkicon> always uses its built-in inline renderer.
Example:
IconManager
The main service responsible for loading and rendering icons is:
It is registered as a Laravel singleton.
You can resolve it from the container:
Get an Icon
You can retrieve an icon as a complete SVG:
By default, the icon type is:
To specify another type:
Get the Raw SVG Path
The render argument can be disabled to retrieve only the SVG path/content:
This is useful when the SVG element itself needs to be controlled by a Blade component or custom renderer.
SVG Attributes
When rendering an icon directly through IconManager, attributes can be passed as an array:
The package escapes attribute names and values before rendering them.
Check Whether an Icon Exists
For a specific type:
The result is a boolean.
Get Icon Names
Get all icon names for a specific type:
Get icon names grouped by type:
Get All Icons
Get all icons as raw path definitions:
Get all icons as rendered SVG elements:
Icon JSON Format
Icons are stored as JSON objects where the key is the icon name and the value is the SVG path/content.
Example:
Icon names must match:
Invalid icon names are ignored while loading the JSON file.
Empty or invalid path values are also ignored.
Cache
Icon loading can be cached.
Caching is disabled by default:
Enable it through the environment:
The default cache TTL is 24 hours:
You can customize the cache key:
Or configure it directly in:
Example:
Clearing the Icon Cache
The package provides:
To clear the icon cache:
For example:
This is useful after changing or replacing icon JSON files while caching is enabled.
Debugging Missing Icons
If an icon does not exist and Laravel is running with:
the package renders a small warning indicator:
with the missing icon name.
When debug mode is disabled, missing icons return an empty string instead.
Creating Custom Icons
You can add your own icon collection.
For example, create:
with:
Then configure it:
You can then use:
Blade Registration
The package registers the following Blade components:
Their aliases are registered by the service provider:
Security
Icon names and icon types are validated before lookup.
Only identifiers matching:
are accepted.
HTML attributes generated by IconManager are escaped using:
Icon path content is treated as SVG content and is inserted directly into the generated SVG. Therefore, custom icon JSON files should only contain trusted SVG definitions.
License
This package is open-sourced software licensed under the MIT license.
Author
Sina Zangiband
Email:
Contact
GitHub
Repository: