PHP code example of tonegabes / filament-better-options
1. Go to this page and download the library: Download tonegabes/filament-better-options 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/ */
tonegabes / filament-better-options example snippets
use ToneGabes\BetterOptions\Forms\Components\CheckboxCards;
use ToneGabes\Filament\Icons\Enums\Phosphor;
// Checkbox Cards with default features
CheckboxCards::make('permissions')
->label('Permissions')
->columns(2)
->options([
'view' => 'View',
'edit' => 'Edit',
'delete' => 'Delete',
'create' => 'Create',
])
->descriptions([
'view' => 'Allows viewing the model.',
'edit' => 'Allows editing the model.',
'delete' => 'Allows deleting the model.',
'create' => 'Allows creating a new model.',
])
->icons([
'view' => Phosphor::Eye->thin(),
'edit' => Phosphor::Pencil->thin(),
'delete' => Phosphor::Trash->thin(),
'create' => Phosphor::Plus->thin(),
])
,
use ToneGabes\BetterOptions\Forms\Components\CheckboxList;
use ToneGabes\Filament\Icons\Enums\Phosphor;
// Checkbox List with default features
CheckboxList::make('permissions')
->label('Permissions')
->options([
'view' => 'View',
'edit' => 'Edit',
'delete' => 'Delete',
'create' => 'Create',
])
->descriptions([
'view' => 'Allows viewing the model.',
'edit' => 'Allows editing the model.',
'delete' => 'Allows deleting the model.',
'create' => 'Allows creating a new model.',
])
->icons([
'view' => Phosphor::Eye->thin(),
'edit' => Phosphor::Pencil->thin(),
'delete' => Phosphor::Trash->thin(),
'create' => Phosphor::Plus->thin(),
])
,
use ToneGabes\BetterOptions\Forms\Components\RadioCards;
use ToneGabes\Filament\Icons\Enums\Phosphor;
// Radio Cards with default features
RadioCards::make('role')
->label('Role')
->columns(2)
->options([
'manager' => 'Manager',
'editor' => 'Editor',
'viewer' => 'Viewer',
'creator' => 'Creator',
])
->descriptions([
'manager' => 'Allows managing the model.',
'editor' => 'Allows editing the model.',
'viewer' => 'Allows viewing the model.',
'creator' => 'Allows creating a new model.',
])
->icons([
'manager' => Phosphor::Gear->thin(),
'editor' => Phosphor::Pencil->thin(),
'viewer' => Phosphor::Eye->thin(),
'creator' => Phosphor::Plus->thin(),
])
,
use ToneGabes\BetterOptions\Forms\Components\RadioList;
use ToneGabes\Filament\Icons\Enums\Phosphor;
// Radio List with default features
RadioList::make('role')
->label('Role')
->options([
'manager' => 'Manager',
'editor' => 'Editor',
'viewer' => 'Viewer',
'creator' => 'Creator',
])
->descriptions([
'manager' => 'Allows managing the model.',
'editor' => 'Allows editing the model.',
'viewer' => 'Allows viewing the model.',
'creator' => 'Allows creating a new model.',
])
->icons([
'manager' => Phosphor::Gear->thin(),
'editor' => Phosphor::Pencil->thin(),
'viewer' => Phosphor::Eye->thin(),
'creator' => Phosphor::Plus->thin(),
])
,
use Filament\Support\Contracts\HasDescription;
use Filament\Support\Contracts\HasIcon;
use Filament\Support\Contracts\HasLabel;
use ToneGabes\BetterOptions\Contracts\HasExtraText;
use ToneGabes\Filament\Icons\Enums\Phosphor;
enum Roles: string implements HasDescription, HasExtraText, HasIcon, HasLabel {
case Manager = 'manager';
case Editor = 'editor';
case Viewer = 'viewer';
case Creator = 'creator';
public function getDescription(): string {
return match($this) {
self::Manager => 'Allows managing the model.',
self::Editor => 'Allows editing the model.',
self::Viewer => 'Allows viewing the model.',
self::Creator => 'Allows creating a new model.',
};
}
public function getExtraText(): string {
return match($this) {
self::Manager => 'model.manager',
self::Editor => 'model.editor',
self::Viewer => 'model.viewer',
self::Creator => 'model.creator',
};
}
public function getIcon(): string {
return match($this) {
self::Manager => Phosphor::Gear->thin(),
self::Editor => Phosphor::Pencil->thin(),
self::Viewer => Phosphor::Eye->thin(),
self::Creator => Phosphor::Plus->thin(),
};
}
public function getLabel(): string {
return match($this) {
self::Manager => 'Manager',
self::Editor => 'Editor',
self::Viewer => 'Viewer',
self::Creator => 'Creator',
};
}
}
RadioList::make('role')
->label('Role')
->enum(Roles::cases())
// No need to specify these if enum is using filament enum contracts
// ->descriptions()
// ->icons()
// ->extraTexts()
,
RadioCards::make('role')
->label('Role')
->columns(2)
->enum(Roles::class)
->partiallyHiddenIndicator()
->itemsCenter()
->iconAfter()
->indicatorBefore()
// ->hiddenIndicator() // You also can totaly hide the indicator
,