Basics
Contains all Basic Methods.
The Range
field allows you to set a range of values.
Basic Methods
Creation
Since the range has two values, you need to specify them using the fromTo()
method.
fromTo(string $fromField, string $toField)
fromTo(string $fromField, string $toField)
use MoonShine\UI\Fields\Range;Range::make('Age', 'age')->fromTo('age_from', 'age_to')
use MoonShine\UI\Fields\Range;Range::make('Age', 'age')->fromTo('age_from', 'age_to')
Attributes
If you need to add custom attributes for the fields, you can use the corresponding fromAttributes()
and toAttributes()
methods.
fromAttributes(array $attributes)
fromAttributes(array $attributes)
toAttributes(array $attributes)
toAttributes(array $attributes)
In this example, a placeholder is added.
Range::make('Age')->fromTo('age_from', 'age_to')->fromAttributes(['placeholder' => 'from'])->toAttributes(['placeholder' => 'to'])
Range::make('Age')->fromTo('age_from', 'age_to')->fromAttributes(['placeholder' => 'from'])->toAttributes(['placeholder' => 'to'])
Methods for Working with Numeric Values
Max and Min Values
The min()
and max()
methods are used to set the minimum and maximum values of the field.
min(int|float $min)
min(int|float $min)
max(int|float $max)
max(int|float $max)
Step
The step()
method is used to specify the step value for the field.
step(int|float $step)
step(int|float $step)
Range::make('Price')->fromTo('price_from', 'price_to')->min(0)->max(10000)->step(5)
Range::make('Price')->fromTo('price_from', 'price_to')->min(0)->max(10000)->step(5)
Stars
The stars()
method is used to display the numeric value in preview mode as stars (e.g., for ratings).
stars()
stars()
Range::make('Rating')->fromTo('rating_from', 'rating_to')->stars()
Range::make('Rating')->fromTo('rating_from', 'rating_to')->stars()
Filter
When using the Range
field for building a filter, the fromTo()
method is not used, as filtering occurs on a single field in the database table.
Range::make('Age', 'age')
Range::make('Age', 'age')