https://github.com/orchidsoftware/blade-icons
Effortlessly integrate SVG images into your Blade templates with this convenient package, offering a seamless way to work with inline icons.
https://github.com/orchidsoftware/blade-icons
blade blade-templates icon icons inline-svg-images
Last synced: about 2 months ago
JSON representation
Effortlessly integrate SVG images into your Blade templates with this convenient package, offering a seamless way to work with inline icons.
- Host: GitHub
- URL: https://github.com/orchidsoftware/blade-icons
- Owner: orchidsoftware
- License: mit
- Created: 2020-06-24T21:22:45.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-25T18:44:27.000Z (3 months ago)
- Last Synced: 2025-04-09T22:22:11.652Z (about 2 months ago)
- Topics: blade, blade-templates, icon, icons, inline-svg-images
- Language: PHP
- Homepage: https://orchid.software
- Size: 66.4 KB
- Stars: 21
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Inline SVG Icons for Laravel Blade
This package for the Laravel framework allows you to use Blade components to insert inline SVG images.
## Installation
To install this package, run the following command in your command line:
```php
$ composer require orchid/blade-icons
```## Basic Usage
To register a directory with your files in the service provider, use the following code:
```php
namespace App\Providers;use Orchid\Icons\IconFinder;
use Illuminate\Support\ServiceProvider;class AppServiceProvider extends ServiceProvider
{
public function boot(IconFinder $iconFinder) : void
{
$iconFinder->registerIconDirectory('fa', storage_path('app/fontawesome'));
}
}
```When calling the directory method with the first argument, we pass the prefix to call our icons and the second argument is the directory where they are located.
After that, we can call the component in our blade templates:
```blade
```
If you use one or two sets of icons that do not repeat, then it is not necessary to specify a prefix in the component:
```blade
```
You can also list some attributes that should be applied to your icon:
```blade
```
Static call from a PHP class:
```php
IconComponent::make(
path: 'fa.home',
id: 101,
class: 'red',
);
```### Default Sizes
If you are using icons from the same set, it makes sense to specify a default size value:
```php
namespace App\Providers;use Orchid\Icons\IconFinder;
use Illuminate\Support\ServiceProvider;class AppServiceProvider extends ServiceProvider
{
public function boot(IconFinder $iconFinder): void
{
$iconFinder
->registerIconDirectory('fa', storage_path('app/fontawesome'))
->setSize('54px', '54px');
}
}
```If you use different sets, for example, in the public part of the application and in the admin panel, then you can dynamically change the value in the middleware:
```php
namespace App\Http\Middleware;use Closure;
use Illuminate\Http\Request;
use Orchid\Icons\IconFinder;class ExampleMiddleware
{
public function __construct(
private IconFinder $iconFinder
) {}/**
* Handle an incoming request.
*/
public function handle(Request $request, Closure $next): mixed
{
$this->iconFinder->setSize('54px', '54px');return $next($request);
}
}
```