Skip to content

owen-soak/nova-date-range-filter

 
 

Repository files navigation

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 owen-soak/nova-date-range-filter

How to use

Just use DateRangeFilter class instead of Filter

use Owensoak\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")

About

A Laravel Nova date range filter.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CSS 81.5%
  • Vue 12.8%
  • PHP 4.5%
  • JavaScript 1.2%