Fields

DateRange

Basics

Contains all Basic methods.

Creation

The DateRange field allows you to select a date range. Since the date range has two values, they must be specified using the fromTo() method.

fromTo(string $fromField, string $toField)
use MoonShine\UI\Fields\DateRange;
 
DateRange::make('Dates')
->fromTo('date_from', 'date_to')

Date and Time

Using the withTime() method allows you to enter both date and time in the fields.

withTime()
DateRange::make('Dates')
->fromTo('date_from', 'date_to')
->withTime()

Format

The format() method allows you to change the display format of the field values in the preview.

format(string $format)
DateRange::make('Dates')
->fromTo('date_from', 'date_to')
->format('d.m.Y')

Attributes

The DateRange field has attributes that can be set using the corresponding methods. The min() and max() methods are used to set the minimum and maximum date values.

min(string $min)
max(string $max)

The step() method is used to set the date step for the field.

step(int|float|string $step)
DateRange::make('Dates')
->fromTo('date_from', 'date_to')
->min('2024-01-01')
->max('2024-12-31')
->step(5)

If you need to add custom attributes for the fields, you can use the corresponding methods fromAttributes() and toAttributes().

fromAttributes(array $attributes)
toAttributes(array $attributes)
DateRange::make('Dates')
->fromTo('date_from', 'date_to')
->fromAttributes(['class'=> 'bg-black'])
->toAttributes(['class'=> 'bg-white'])

Filter

When using the DateRange field to build a filter, the fromTo() method is not used, as filtering occurs by one field in the database table.

DateRange::make('Dates', 'dates')