idez/nova-date-range-filter

A Laravel Nova date range filter.
119,738 2
Install
composer require idez/nova-date-range-filter
Latest Version:2.2.0
PHP:^8.1
License:MIT
Last Updated:Apr 15, 2024
Links: GitHub  ·  Packagist
Maintainer: rafaellaurindo

Laravel Nova Date Range Filter

License Latest Stable Version Total Downloads

About

This is a configurable and ready to use filter for Laravel Nova 4 based on Nova's own date filter that displays a date range picker.

Installation

To install the filter run the following command in your Laravel Nova project:

composer require idez/nova-date-range-filter

Usage

Simply add this filter to the filters method in your Nova resource.

use Illuminate\Http\Request;
use Idez\DateRangeFilter\DateRangeFilter;

class CustomResource extends Resource
{
    public function filters(Request $request): array
    {
        return [
            new DateRangeFilter(),
        ];
    }
}

By default, this will create a filter named "Created at" which applies the selected date range to the created_at database column.

Customization

The filter takes up to three arguments to customize it to your needs.

Configuration

All available settings are provided by the included Config enum. See the full example below how to use it.

Full Example

use Illuminate\Http\Request;
use Idez\DateRangeFilter\DateRangeFilter;
use Idez\DateRangeFilter\Enums\Config;

class CustomResource extends Resource
{
    public function filters(Request $request): array
    {
        return [
            new DateRangeFilter('Created at', 'created_at', [
                Config::ALLOW_INPUT => false,
                Config::DATE_FORMAT => 'Y-m-d',
                Config::DEFAULT_DATE => ['2019-06-01', '2019-06-30'],
                Config::DISABLED => false,
                Config::ENABLE_TIME => false,
                Config::ENABLE_SECONDS => false,
                Config::FIRST_DAY_OF_WEEK => 0,
                Config::LOCALE => 'default',
                Config::MAX_DATE => '2019-12-31',
                Config::MIN_DATE => '2019-01-01',
                Config::PLACEHOLDER => __('Choose date range'),
                Config::SHORTHAND_CURRENT_MONTH => false,
                Config::SHOW_MONTHS => 1,
                Config::TIME24HR => false,
                Config::WEEK_NUMBERS => false,
            ]),
        ];
    }
}

Screenshots

Contributing

Contributions are welcome, explain the issue/feature that you want to solve/add and back your code up with tests. Happy coding!

License

This package was originally developed by https://github.com/pos-lifestyle/laravel-nova-date-range-filter however they have abandoned the package. The MIT License (MIT). Please see License File for more information.

Related Packages

pos-lifestyle/laravel-nova-date-range-filter

A Laravel Nova date range filter.

184,054 16
ampeco/nova-date-range-filter

A Laravel Nova date range filter.

1,059,902 35
marshmallow/nova-calendar

A powerful event calendar Tool for Laravel's Nova 5.

5,971 0
optimistdigital/nova-detached-filters

This Laravel Nova package allows you to detach filters from the filter dropdown

244,617 63
mahi/spatie-tags-nova-filter

A Laravel Nova filter for Spatie/Laravel-Tags.

15,878 3