Basics
Contains all basic methods.
The Checkbox field is a field for selecting a yes/no value.
Creation
use MoonShine\UI\Fields\Checkbox; Checkbox::make('Publish', 'is_publish')
<x-moonshine::form.wrapper label="Publish"> <x-moonshine::form.input type="checkbox" name="is_publish" /></x-moonshine::field-container>
On/Off Values
By default, the field has values 1
and 0
for selected and unselected states respectively. The onValue()
and offValue()
methods allow you to override these values.
onValue(int|string $onValue)
offValue(int|string $offValue)
Checkbox::make('Publish', 'is_publish') ->onValue('yes') ->offValue('no')
Preview Editing
The updateOnPreview()
method allows editing the Checkbox field in preview mode.
updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
-
$url
- url for handling asynchronous requests, -
$resource
- model resource that the relation refers to, -
$condition
- condition for executing the method.
The settings are optional and should be provided if the field is working outside of a resource.
Checkbox::make('Public') ->updateOnPreview()
Preview Editing
This field supports preview editing.
Reactivity
This field supports reactivity.