Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages
N

Date Range Filter

Readme

Date Range Filter for Laravel Nova

Nova filter that displays a Date Range Picker instead of a select.

Install

Run this command in your nova project: composer require ampeco/nova-date-range-filter

How to use

Just use DateRangeFilter class instead of Filter

use Ampeco\Filters\DateRangeFilter;

class DateRange extends DateRangeFilter
{
    public function apply(Request $request, $query, $value)
    {
        $from = Carbon::parse($value[0])->startOfDay();
        $to = Carbon::parse($value[1])->endOfDay();

        return $query->whereBetween('created_at', [$from, $to]);
    }

    /**
     * Get the filter's available options.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    // public function options(Request $request)
    // {
    //     return [
    //         'firstDayOfWeek' => 0,
    //         'separator' => '-',
    //         'enableTime' => false,
    //         'enableSeconds' => false,
    //         'twelveHourTime' => false
    //     ];
    // }
}

Customization

Use fluent interface to configure your DateRange filter

(new DateRange)->placeholder("Placeholder")->dateFormat("m d Y")

In range mode a filter can limit the length of the range. After the first day is clicked, only days within the limit can be picked; a range that is longer or has one date is not applied, and the matching message is shown under the filter. The filter can still be cleared.

(new DateRange)->maxRangeDays(60, "The selected period exceeds 60 days.", "Select both a start date and an end date.")

A filter that must always be applied, for example one with a default value, can be marked always active. Its clear button is hidden, an emptied input goes back to the applied value, and "Reset filters" shows the filter's default value again instead of an empty input.

(new DateRange)->alwaysActive()

With time enabled, a range picked in the calendar ends at the time shown in the time input. To end it at 23:59 of its last day instead, so that a picked range covers whole days:

(new DateRange)->enableTime()->pickedRangeEndsAtEndOfDay()

Screenshots

Reviews

★ ★ ★ ★ ★

By denisvasilievclarity on August 23, 2023

Doesn't work.

★ ★ ★ ★ ★

By echocage123 on March 12, 2023

Unable to select date interval

★ ★ ★ ★ ★

By Jose Erick Carreon on September 24, 2022

This doesn't work if you don't add " 'mode' => 'range', " to options.

★ ★ ★ ★ ★

By osama on August 4, 2022

good filter

★ ★ ★ ★ ★

By Tim on May 12, 2022

For the people trying to use this. It defaults to single mode. So add 'mode' => 'range' to your options method in the filter.

★ ★ ★ ★ ★

By Geert Lucas on March 8, 2022

Does not work. Selecting ranges not possible

★ ★ ★ ★ ★

By Mira Thakkar on January 27, 2022

It is not working in the way of not able to select two dates. Can you please provide proper solution or documentation of that

★ ★ ★ ★ ★

By Valeriu Vodnicear on November 12, 2021

interval can't be selected

Back to Top
Added 7 years ago
Last updated 2 Weeks Ago
Version 0.2.3
Composer
ampeco/nova-date-range-filter
GitHub stars 35
Packagist downloads 1,084,808

Favorites

36 users favorited

Rating

2.90
(out of 5)
★★★★★
★★★★
★★★
★★
★
13 ratings

Author

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas