Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages
L

Date Range Field

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.

Reviews

By denisvasilievclarity on March 31, 2023

Doesn't work correctly. After save , can't view normally range and doesn't correct edit

Back to Top
Added 3 years ago
Last updated 9 Months Ago
Version 5.0.0
Composer
marshmallow/nova-date-range-field
GitHub stars 3
Packagist downloads 10,470

Favorites

0 users favorited

Rating

1.00
(out of 5)
★★★★★
★★★★
★★★
★★
1 ratings

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas