Skip to main content

Introduction

The toggle component, similar to a checkbox, allows you to interact a boolean value.
If youโ€™re saving the boolean value using Eloquent, you should be sure to add a boolean cast to the model property:

Adding icons to the toggle button

Toggles may also use an icon to represent the โ€œonโ€ and โ€œoffโ€ state of the button. To add an icon to the โ€œonโ€ state, use the onIcon() method. To add an icon to the โ€œoffโ€ state, use the offIcon() method:

Customizing the color of the toggle button

You may also customize the color representing the โ€œonโ€ or โ€œoffโ€ state of the toggle. To add a color to the โ€œonโ€ state, use the onColor() method. To add a color to the โ€œoffโ€ state, use the offColor() method:

Positioning the label above

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:
When the toggle is stacked, its label is above it:

Toggle validation

As well as all rules listed on the validation page, there are additional rules that are specific to toggles.

Accepted validation

You may ensure that the toggle is โ€œonโ€ using the accepted() method:
Optionally, you may pass a boolean value to control if the validation rule should be applied or not:

Declined validation

You may ensure that the toggle is โ€œoffโ€ using the declined() method:
Optionally, you may pass a boolean value to control if the validation rule should be applied or not: