mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-24 23:35:30 +08:00
1.9 KiB
1.9 KiB
title
| title |
|---|
| Toggle |
The toggle component, similar to a checkbox, allows you to interact a boolean value.
use Filament\Forms\Components\Toggle;
Toggle::make('is_admin')
Toggle fields have two layout modes, inline and stacked. By default, they are inline.
When the toggle is inline, its label is adjacent to it:
use Filament\Forms\Components\Toggle;
Toggle::make('is_admin')->inline()
When the toggle is stacked, its label is above it:
use Filament\Forms\Components\Toggle;
Toggle::make('is_admin')->inline(false)
Toggles may also use an "on icon" and an "off icon". These are displayed on its handle and could provide a greater indication to what your field represents. The parameter to each method must contain the name of a Blade icon component:
use Filament\Forms\Components\Toggle;
Toggle::make('is_admin')
->onIcon('heroicon-m-bolt')
->offIcon('heroicon-m-user')
You may also customize the color representing each state. These may be either primary, secondary, success, warning or danger:
use Filament\Forms\Components\Toggle;
Toggle::make('is_admin')
->onColor('success')
->offColor('danger')
If you're saving the boolean value using Eloquent, you should be sure to add a boolean cast to the model property:
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $casts = [
'is_admin' => 'boolean',
];
// ...
}


