PHP code example of asignua / filament-toggle-icon-column
1. Go to this page and download the library: Download asignua/filament-toggle-icon-column 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/ */
asignua / filament-toggle-icon-column example snippets
use Asignua\FilamentToggleIconColumn\Columns\ToggleIconColumn;
use Filament\Support\Enums\IconSize;
ToggleIconColumn::make('is_active')
->onIcon('heroicon-s-check-circle')
->offIcon('heroicon-o-x-circle')
->onColor('success')
->offColor('gray')
->size(IconSize::Large)
->tooltip('Toggle active'),
ToggleIconColumn::make('is_published')
->rules(['boolean']) // default; an error shows in the tooltip and the icon reverts
->beforeStateUpdated(fn (Post $record, bool $state) => ...)
->afterStateUpdated(fn (Post $record, bool $state) => ...)
->updateStateUsing(fn (Post $record, bool $state) => $record->publish($state)); // replaces the default write
->disabled(fn (Post $record): bool => $record->is_archived) // greyed out, and the server refuses to write
->authorize() // default: Gate `update` on the record, only when the model has a policy
->authorize('publish') // another ability
->authorize(false) // skip the policy check (core ToggleColumn behaviour)
->authorize(fn (Task $record): bool => ! $record->is_locked) // closure gate: false denies, true allows (the policy is not asked)
->authorize(fn (): string => 'publish') // closure returning a string: the ability to check
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.