How do I create a date range admin filter?

To create a date range admin filter you need to create a class that extends Aero\Admin\Filters\DateRangeAdminFilter and implements the handleDateRange method.

 

handleDateRange Method

This method is executed when a date is set and accepts 3 parameters. The first parameter is a Carbon object for the selected start date, the second parameter is a Carbon object for the selected end date, and the third parameter is the query.

 

<?php

namespace Acme\MyModule\Filters;

use Aero\Admin\Filters\DateRangeAdminFilter;

class CreatedAtAdminFilter extends DateRangeAdminFilter
{
   protected function handleDateRange($startDate, $endDate, $query)
   {
       $query->whereBetween('created_at', [$startDate, $endDate]);
   }
}

Articles in this section

Was this article helpful?
0 out of 0 found this helpful