ampeco / nova-date-range-filter by sash
forked from 64robots/nova-date-filter

A Laravel Nova date range filter.
836,701
36
2
Package Data
Maintainer Username: sash
Package Create Date: 2019-04-05
Package Last Update: 2024-01-03
Home Page:
Language: CSS
License: MIT
Last Refreshed: 2024-11-24 15:06:34
Package Statistics
Total Downloads: 836,701
Monthly Downloads: 10,212
Daily Downloads: 57
Total Stars: 36
Total Watchers: 2
Total Forks: 34
Total Open Issues: 3

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")