Introduction
The toggle column renders a toggle button for inline boolean editing:
use Filament\Tables\Columns\ToggleColumn;
ToggleColumn::make('is_admin')
Basic usage
The toggle column provides a visual switch that updates the database when toggled:
ToggleColumn::make('is_featured')
ToggleColumn::make('is_published')
ToggleColumn::make('is_active')
Customizing colors
You can customize the colors for the on and off states:
ToggleColumn::make('is_active')
->onColor('success')
->offColor('danger')
color
string | array | Closure
default:"'primary' for on, 'gray' for off"
The color when toggled on or off.
Customizing icons
Customize the icons for the on and off states:
use Filament\Support\Icons\Heroicon;
ToggleColumn::make('is_active')
->onIcon(Heroicon::OutlinedCheckCircle)
->offIcon(Heroicon::OutlinedXCircle)
icon
string | BackedEnum | Htmlable | Closure
The icon to display when toggled on or off.
Validation
By default, the toggle column validates the input as a boolean:
ToggleColumn::make('is_admin')
->rules(['required', 'boolean'])
Lifecycle hooks
Execute code before and after the toggle state is updated:
ToggleColumn::make('is_active')
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database
// You can perform checks or prepare data here
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database
// You can trigger notifications, update related records, etc.
})
Example: Logging changes
ToggleColumn::make('is_published')
->afterStateUpdated(function ($record, $state) {
activity()
->performedOn($record)
->withProperties(['published' => $state])
->log($state ? 'published' : 'unpublished');
})
Disabling the toggle
You can disable the toggle conditionally:
ToggleColumn::make('is_admin')
->disabled(fn ($record) => $record->is_super_admin)
Add tooltips to provide context:
ToggleColumn::make('is_featured')
->tooltip('Feature this post on the homepage')