marshmallow/nova-date-range-field

A Laravel Nova field.

Maintainers

Package info

github.com/marshmallow-packages/nova-date-range-field

Language:CSS

pkg:composer/marshmallow/nova-date-range-field

Statistics

Installs: 10 430

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

5.0.0 2025-08-28 14:13 UTC

This package is auto-updated.

Last update: 2026-06-11 15:52:36 UTC


README

alt text

Date Range Field for Laravel Nova

Latest Version on Packagist Total Downloads

A Laravel Nova field that provides a date range picker (powered by flatpickr). It can store a range across two model attributes (a "from" and a "till"), as a single value, or as JSON.

Installation

Install the package via Composer in your Nova project:

composer require marshmallow/nova-date-range-field

The field's assets are registered automatically through Marshmallow\NovaDateRangeField\FieldServiceProvider (Laravel package auto-discovery), so there is nothing else to publish or configure.

Usage

Use the DateRange field on a Nova resource and define the names of the from and till attributes together with the label. If no fields are set, the string value is stored in the database column of the field's attribute.

use Marshmallow\NovaDateRangeField\DateRange;

public function fields(Request $request)
{
    return [
        DateRange::make(__('Access Date'), ['from', 'till']),
        // OR
        DateRange::make(__('Access Date'))
            ->fields('from', 'till'),
    ];
}

flatpickr options

Additional flatpickr options can be passed through the options array. These overwrite the field's default options (weekNumbers, defaultHour, defaultMinute).

DateRange::make(__('Date range'))
    ->fields('from', 'till')
    ->options([
        'defaultHour' => 0,
        'defaultMinute' => 0,
    ]),

Field options

The available chainable options (with their default behaviour) are:

->modeType('range')   // Set the picker mode ('range' or 'single')
->range()             // Range mode (default)
->single()            // Single date mode
->twelveHourTime()    // Twelve hour time display
->enableSeconds()     // Enable seconds in the time picker
->separator('-')      // Separator shown between the from/till values
->firstDayOfWeek(1)   // First day of the week
->enableTime()        // Enable the time picker
->dateFormat('Y-m-d') // flatpickr date format
->placeholder('date range')
->saveAsJSON()        // Store the value as JSON instead of separate columns

When saveAsJSON() is used (or when the field's attribute is cast to array on the model), the range is stored as JSON on a single attribute instead of being split across the from and till columns.

Credits

Security Vulnerabilities

Please report security vulnerabilities by email rather than via the public issue tracker.

License

The MIT License (MIT). Please see the License File for more information.