-Make -Default value -Only for reading -Placeholder -Attributes -Stars -+/-buttons -Editing in preview
Extends Text
- has the same features
Make
The Number field is an extension of Text, which by default sets type=number
and has additional methods.
use MoonShine\Fields\Number; //... public function fields(): array{ return [ Number::make('Sort') ];} //...
Default value
You can use the default()
method if you need to specify a default value for a field.
default(mixed $default)
use MoonShine\Fields\Number; //... public function fields(): array{ return [ Number::make('Title') ->default(2) ];} //...
Only for reading
If the field is read-only, then you must use the readonly()
method.
readonly(Closure|bool|null $condition = null)
use MoonShine\Fields\Number; //... public function fields(): array{ return [ Number::make('Title') ->readonly() ];} //...
Placeholder
The placeholder()
method allows you to set placeholder attribute on the field.
placeholder(string $value)
use MoonShine\Fields\Number; //... public function fields(): array{ return [ Number::make('Rating', 'rating') ->nullable() ->placeholder('Product rating') ];} //...
Attributes
The Number field has additional attributes, which can be set through the appropriate methods.
Methods min()
and max()
are used to set the minimum and maximum values of a field.
min(int|float $min)
max(int|float $max)
The step()
method is used to specify a step value for a field.
step(int|float $step)
use MoonShine\Fields\Number; //...public function fields(): array{ return [ Number::make('Price') ->min(0) ->max(100000) ->step(5) ];} //...
Stars
The stars()
method is used to display a numeric value when previewing in the form of stars (for example, for ratings).
stars()
use MoonShine\Fields\Number; //... public function fields(): array{ return [ Number::make('Rating') ->stars() ->min(1) ->max(10) ];} //...
+/- buttons
The buttons()
method allows you to add buttons to a field for increasing or decreasing a value.
buttons()
use MoonShine\Fields\Number; //... public function fields(): array{ return [ Number::make('Rating') ->buttons() ];} //...
Editing in preview
The updateOnPreview()
method allows you to edit the Number 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\Number; //... public function fields(): array{ return [ Number::make(Country) ->updateOnPreview() ];} //...