Checkbox

# Make

The Checkbox field includes all the basic methods.

use MoonShine\Fields\Checkbox;
 
//...
 
public function fields(): array
{
return [
Checkbox::make('Publish', 'is_publish')
];
}
 
//...

# On/off values

By default, the field has the values 1 and 0 for the selected and unselected states, respectively. The onValue() and offValue() methods allow you to override these values.

onValue(int|string $onValue)
offValue(int|string $onValue)
use MoonShine\Fields\Checkbox;
 
//...
 
public function fields(): array
{
return [
Checkbox::make('Publish', 'is_publish')
->onValue('yes')
->offValue('no')
];
}
 
//...

# Editing in preview

The updateOnPreview() method allows you to edit the Checkbox field in preview mode.

updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
  • $url - url for asynchronous request processing,
  • $resource - model resource referenced by the relationship,
  • $condition - method run condition.

The settings are not required and must be passed if the field is running out of resource.

use MoonShine\Fields\Checkbox;
 
//...
 
public function fields(): array
{
return [
Checkbox::make(Public)
->updateOnPreview()
];
}
 
//...