alkoumi/filament-image-radio-button

Filament Form Radio Button But With Images

v1.1.2 2025-03-09 11:45 UTC

This package is auto-updated.

Last update: 2025-03-09 13:30:27 UTC


README

RTL & Dark Mode Supported 🎉

Total Downloads Packagist Stars License Latest Version on Packagist GitHub release (latest by date) GitHub Tests Action Status

If you want Filament field to choose and select an Image from a group of images with a Radio button This is Image Radio button to replacing traditional radio buttons with images selection.

filament-image-radio-button.gif

Installation

You can install the package via composer:

composer require alkoumi/filament-image-radio-button

Important

1- OPTIONS

The radio buttom has options then the scenario Here is you have Model Report and you want to choose a design of a report

so options here must return return Report::pluck('file', 'id')->toArray(); the options will be like

[ 1 => reort1.jpg , 2 => reort2.jpg] then the user will choose the design.

2- Images

You must define where you stored the images in filesystems disks somthing like local or public so in this example I am using ->disk('reports') So the component can find the images files

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app/private'),
        'serve' => true,
        'throw' => false,
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL') . '/storage',
        'visibility' => 'public',
        'throw' => false,
    ],

    'reports' => [
        'driver' => 'local',
        'root' => storage_path('app/public/reports'),
        'url' => env('APP_URL') . '/reports',
        'visibility' => 'public',
        'throw' => false,
    ],

Usage in basic scenario

use Alkoumi\FilamentImageRadioButton\Forms\Components\ImageRadioGroup;

ImageRadioGroup::make('report_id')
                    ->disk('reports')
                    ->options(fn (Get $get) => Report::whereType($get('type_id'))->pluck('file', 'id')->toArray()),

Usage in advanced scenario

use Alkoumi\FilamentImageRadioButton\Forms\Components\ImageRadioGroup;

ImageRadioGroup::make('report_id')
                    ->animation(true)
                    ->required()
                    ->label(__('Report Design'))
                    ->disk('reports')
                    ->options(fn (Get $get) => Report::whereType($get('type_id'))->pluck('file', 'id')->toArray())
                    ->afterStateUpdated(fn(Get $get, Set $set, ?string $state) => $set('reportdesign', ['report' => Report::find($state), 'date' => explode(' ', $get('report_date'))[0]])) 
                    ->live(),

Screenshots

filament-plugin-modes.jpg

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.