PHP code example of abdulrahman-dev22 / filament-icon-picker

1. Go to this page and download the library: Download abdulrahman-dev22/filament-icon-picker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abdulrahman-dev22 / filament-icon-picker example snippets


use AbdulrahmanDev22\FilamentIconPicker\Forms\Components\IconPicker;

IconPicker::make('icon')
    ->

// config/filament-icon-picker.php
'heroicons' => [
    'label' => 'Heroicons',
    'styles' => ['o', 's'], // o = outline, s = solid, m = mini, c = micro
],

IconPicker::make('icon')
    ->customIconsPath(resource_path('svg/brand'), key: 'brand', label: 'Brand Icons');

// config/filament-icon-picker.php
'custom_icon_sets' => [
    'brand' => [
        'path' => resource_path('svg/brand'),
        'label' => 'Brand Icons',
    ],
],

IconPicker::make('icon')
    ->customIconsPath(resource_path('svg/brand'), 'brand', 'Brand')
    ->customIconsPath(resource_path('svg/flags'), 'flags', 'Flags')
    ->columns(10);

IconPicker::make('icon')->withoutIconSet('heroicons');   // or ->withoutHeroicons()
IconPicker::make('icon')->withoutIconSet('heroicons', 'brand');
IconPicker::make('icon')->withoutGlobalIconSets()->customIconsPath(...); // only this field's sets

namespace App\Support\Icons;

use Illuminate\Contracts\Support\Htmlable;
use AbdulrahmanDev22\FilamentIconPicker\IconSets\IconSet;

class StatusIconSet implements IconSet
{
    public function getKey(): string
    {
        return 'status'; // never contains ":"
    }

    public function getLabel(): string
    {
        return 'Status';
    }

    /** @return array<string, string> icon name => label */
    public function getIcons(): array
    {
        return [
            'open' => 'Open',
            'closed' => 'Closed',
            'archived' => 'Archived',
        ];
    }

    /** A Blade Icons name or an Htmlable containing <svg> markup, or null. */
    public function getIcon(string $name): string | Htmlable | null
    {
        return match ($name) {
            'open' => 'heroicon-o-lock-open',
            'closed' => 'heroicon-o-lock-closed',
            'archived' => 'heroicon-o-archive-box',
            default => null,
        };
    }
}

'icon_sets' => [
    \App\Support\Icons\StatusIconSet::class,
],

use AbdulrahmanDev22\FilamentIconPicker\Facades\FilamentIconPicker;

FilamentIconPicker::register(StatusIconSet::class);

IconPicker::make('icon')->icons([new StatusIconSet()]);
IconPicker::make('icon')->icons([new StatusIconSet()], merge: false); // only this set

IconPicker::make('icon')->storeAsArray();          // one field
// config/filament-icon-picker.php
'storage_format' => 'blade_icon',                   // every field

// database/migrations/xxxx_add_icon_to_categories_table.php
Schema::table('categories', function (Blueprint $table) {
    $table->json('icon')->nullable();
});

// app/Models/Category.php
class Category extends Model
{
    protected function casts(): array
    {
        return [
            'icon' => 'array',
        ];
    }
}

use AbdulrahmanDev22\FilamentIconPicker\Facades\FilamentIconPicker;

// Inline SVG as an Htmlable (null when the value is empty / unknown)
FilamentIconPicker::render($category->icon, ['class' => 'h-5 w-5']);

// The underlying Blade Icons name ("heroicon-o-academic-cap", "brand-star") or Htmlable
FilamentIconPicker::resolveIcon($category->icon);

// Table column
IconColumn::make('icon')
    ->icon(fn (?string $state) => FilamentIconPicker::resolveIcon($state));

// app/Http/Resources/CategoryResource.php
public function toArray($request): array
{
    return [
        'name' => $this->name,
        'icon' => FilamentIconPicker::toArray($this->icon),
    ];
}

// config/filament-icon-picker.php
'route' => [
    'enabled' => true,             // or FILAMENT_ICON_PICKER_ROUTE=true
    'prefix' => 'filament-icon-picker',
    'middleware' => [],            // e.g. ['throttle:60,1']
    'max_age' => 31536000,
],

// config/filament-icon-picker.php
'disk_icon_sets' => [
    'uploads' => [
        'disk' => 's3',                 // any disk from config/filesystems.php; null = uploads.disk
        'directory' => 'icon-picker',
        'label' => 'Uploaded Icons',
    ],
],

'uploads' => [
    'set' => 'uploads',                 // default target of ->uploadable(); null = first disk set
    'disk' => env('FILAMENT_ICON_PICKER_DISK'),
    'max_size' => 256,                  // KB
],

IconPicker::make('icon')
    ->uploadable();                                   // everyone who can edit the form
    // ->uploadable(fn () => auth()->user()->can('upload icons'));  // gated
    // ->uploadable(set: 'brand');                    // upload into a specific set

'cache' => [
    'enabled' => env('FILAMENT_ICON_PICKER_CACHE'), // null = only when APP_ENV=production
    'store' => env('FILAMENT_ICON_PICKER_CACHE_STORE'), // null = default cache store
    'ttl' => null, // seconds, null = forever
    'prefix' => 'filament-icon-picker',
],
bash
php artisan filament:assets
bash
php artisan vendor:publish --tag=filament-icon-picker-config
bash
php artisan filament-icon-picker:clear