marshmallow/nova-date-range-filter

A Laravel Nova date range filter.

v2.2.0 2025-02-18 22:22 UTC

README

alt text
Version Issues Licence

Date Range Filter for Laravel Nova

Nova filter that displays a Date Range Picker instead of a select. This field also supports dark-mode, Nova 4 and Nova 5.

Install

Run this command in your nova project:

composer require marshmallow/nova-date-range-filter

How to use

Add the DateRangeFilter to your resource filters array.

public function filters(Request $request)
{
    return [
        new \Marshmallow\Filters\DateRangeFilter('created_at', 'Created date'),
    ];
}

Methods

addRange

With this method, you can set default date ranges that you use frequently. For instance ranges like today, yesterday, this month etc. Please check the example below.

(new DateRangeFilter('created_at', 'Created date'))
    ->addRange('Today', now()->startOfDay(), now()->endOfDay())
    ->addRange('Yesterday', now()->subDay()->startOfDay(), now()->subDay()->endOfDay())
    ->addRange('This week', now()->startOfWeek(), now()->endOfWeek())
    ->addRange('Last 7 days', now()->subDays(7)->startOfDay(), now()->endOfDay())
    ->addRange('Last 30 days', now()->subDays(30)->startOfDay(), now()->endOfDay())
    ->addRange('This month', now()->startOfMonth(), now()->endOfMonth())
    ->addRange('Last month', now()->startOfMonth()->subMonth(1), now()->startOfMonth()->subMonth(1)->endOfMonth())
    ->addRange('This year', now()->startOfYear(), now()->endOfYear()),

showMonths

With this method, it will be possible to show more then just the current month.

enableTime (beta)

Enable the time selector when you select your date.

minTime (beta)

Set a min time that can be selected.

maxTime (beta)

Set a max time that can be selected.

Security

If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.