amidesfahani/nova-persian-date-filter

Laravel Nova Persian Date filter field.

dev-main 2021-05-11 18:08 UTC

This package is auto-updated.

Last update: 2024-11-12 02:03:27 UTC


README

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

Install

Run this command in your nova project: composer require amidesfahani/nova-persian-date-filter

How to use

Just use DateRangeFilter class instead of Filter

use Amid\NovaPersianDateFilter\NovaPersianDateFilter;

class DateRange extends NovaPersianDateFilter
{
    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,
    //         'mode' => 'range',
    //         'enableTime' => false,
    //         'enableSeconds' => false,
    //         'twelveHourTime' => false
    //     ];
    // }
}

Customization

Use fluent interface to configure your DateRange filter

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