PHP code example of syriable / filament-choice-fields
1. Go to this page and download the library: Download syriable/filament-choice-fields 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/ */
syriable / filament-choice-fields example snippets
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxList;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxStackedCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxTable;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioList;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioStackedCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioTable;
CheckboxList::make('delivery_type')
->searchable()
->bulkToggleable()
->options([
'standard' => 'Standard Delivery',
'express' => 'Express Delivery',
'overnight' => 'Overnight Delivery',
'same_day' => 'Same Day Delivery',
])
->descriptions([
'standard' => 'Delivery within 5-7 business days',
'express' => 'Delivery within 2-3 business days',
'overnight' => 'Next day delivery available',
'same_day' => 'Delivery on the same day',
])
->extras([
'standard' => '$5.00 flat rate',
'express' => '$10.00 flat rate',
'overnight' => '$20.00 flat rate',
'same_day' => '$25.00 flat rate',
]);
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\SingleCheckboxCard;
SingleCheckboxCard::make('terms')
->label('Accept terms & conditions')
->description('You agree to our privacy policy and terms of service')
->icon('heroicon-o-shield-check');
SingleCheckboxCard::make('newsletter')
->label('Subscribe to the newsletter')
->description('Get product updates once a month')
->selectedDescription('You will receive our next issue')
->badge('Recommended')
->badgeColor('success')
->color(\Filament\Support\Colors\Color::Emerald)
->hiddenInputs();
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\SingleCheckboxList;
SingleCheckboxList::make('terms')
->label('Accept terms & conditions')
->description('You agree to our privacy policy and terms of service')
->icon('heroicon-o-shield-check');
declare(strict_types=1);
namespace App\Enums;
use Filament\Support\Contracts\HasDescription;
use Filament\Support\Contracts\HasLabel;
enum DeliveryTypeEnum: string implements HasDescription, HasLabel
{
case Standard = 'standard';
case Express = 'express';
case Overnight = 'overnight';
case SameDay = 'same_day';
public function getLabel(): string
{
return match ($this) {
self::Standard => __('Standard Delivery'),
self::Express => __('Express Delivery'),
self::Overnight => __('Overnight Delivery'),
self::SameDay => __('Same Day Delivery'),
};
}
public function getDescription(): string
{
return match ($this) {
self::Standard => __('Delivery within 5-7 business days'),
self::Express => __('Delivery within 2-3 business days'),
self::Overnight => __('Next day delivery available'),
self::SameDay => __('Delivery on the same day'),
};
}
}
use App\Enums\DeliveryTypeEnum;
use Filament\Schemas\Schema;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioStackedCard;
public static function configure(Schema $schema): Schema
{
return $schema
->columns(1)
->components([
RadioStackedCard::make('delivery_type')
->options(DeliveryTypeEnum::class),
]);
}
use Filament\Support\Colors\Color;
CheckboxCard::make('plan')
->options(Plan::class)
->color(Color::Rose);
RadioList::make('language')
->options($languages)
->descriptions([
'en' => 'Click to select this language',
])
->selectedDescriptions([
'en' => 'Selected as the browser language',
]);
use Illuminate\Support\HtmlString;
CheckboxCard::make('plan')
->options([
'basic' => 'Basic',
'pro' => 'Pro',
'team' => 'Team',
])
->extras([
// Escaped automatically.
'basic' => 'Free',
// Rendered as raw HTML because it is Htmlable.
'pro' => str('<span class="font-bold text-primary-600">$29/mo</span>')->toHtmlString(),
// Closures are evaluated per option.
'team' => fn (): HtmlString => new HtmlString('<b>$99/mo</b>'),
]);