ampeco/nova-date-range-filter

A Laravel Nova date range filter.

Installs: 833 874

Dependents: 1

Suggesters: 0

Security: 0

Stars: 36

Watchers: 2

Forks: 45

Language:CSS

0.1.3 2021-09-28 07:55 UTC

This package is auto-updated.

Last update: 2024-11-03 13:24:48 UTC


README

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