Documentation Index
Fetch the complete documentation index at: https://mintlify.com/filamentphp/filament/llms.txt
Use this file to discover all available pages before exploring further.
The toggle component allows you to interact with a boolean value using a switch UI.
Basic Usage
use Filament\Forms\Components\Toggle;
Toggle::make('is_admin')
Available Methods
Controls the label position (inline or stacked).// Inline (default) - label adjacent to toggle
Toggle::make('is_admin')
->inline()
// Stacked - label above toggle
Toggle::make('is_admin')
->inline(false)
Sets the icon displayed when toggled on.use Filament\Support\Icons\Heroicon;
Toggle::make('is_admin')
->onIcon(Heroicon::Bolt)
Sets the icon displayed when toggled off.use Filament\Support\Icons\Heroicon;
Toggle::make('is_admin')
->offIcon(Heroicon::User)
Sets the color when toggled on.Toggle::make('is_admin')
->onColor('success')
Sets the color when toggled off.Toggle::make('is_admin')
->offColor('danger')
Requires the toggle to be on.Toggle::make('terms_of_service')
->accepted()
Requires the toggle to be off.Toggle::make('is_under_18')
->declined()
Common Patterns
Feature Flag
Toggle::make('is_active')
->label('Active')
->onColor('success')
->offColor('gray')
->default(true)
With Icons
use Filament\Support\Icons\Heroicon;
Toggle::make('notifications_enabled')
->label('Enable Notifications')
->onIcon(Heroicon::Bell)
->offIcon(Heroicon::BellSlash)
->onColor('success')
Status Toggle
Toggle::make('published')
->label('Published')
->onColor('success')
->offColor('danger')
->inline()
Database Casting
When saving boolean values with Eloquent, add a boolean cast:
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected function casts(): array
{
return [
'is_admin' => 'boolean',
];
}
}