Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kokarat's avatar

How to create filter date between

I need to filter data by date between date .

Anybody, please suggest to do that.

Thank you.

0 likes
6 replies
Ricardo's avatar

@kokarat use either a whereBetween or two wheres

->whereDate('created_at', '>=', $fromDate)
->whereDate('created_at', '<=', $toDate)
1 like
groar's avatar

@kokarat look in Laravel Nova documentation: https://nova.laravel.com/docs/1.0/filters/defining-filters.html#date-filters

You may generate a date filter using the

nova:filter --date Artisan command.

By default, Nova will place newly generated filters in the app/Nova/Filters directory:

php artisan nova:filter UserType --date

Each date filter generated by Nova contains one method: apply. The apply method is responsible for modifying the query to achieve the desired filter state.

When building date filters, the $value argument passed to the apply method is the string representation of the selected date.

example BirthdayFilter filter:

<?php

namespace App\Nova\Filters;

use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Laravel\Nova\Filters\DateFilter;

class BirthdayFilter extends DateFilter
{
    /**
     * Apply the filter to the given query.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @param  mixed  $value
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function apply(Request $request, $query, $value)
    {
        return $query->where('birthday', '<=', Carbon::parse($value));
    }
}

As you can see in the example above, you may leverage the incoming $value to modify your query. The apply method should return the modified query instance.

kokarat's avatar

@GROAR - Yes, I read already but documents not show or example date between they show only single date

1 like
Cronix's avatar

It's just an eloquent query. So add on multiple where's like mentioned to the apply() method. That's appending a where to the $query in the example, just chain on a 2nd one.

Please or to participate in this conversation.