To create a checkbox list admin filter you need to create a class that extends Aero\Admin\Filters\CheckboxListAdminFilter and implements the handleCheckboxList and checkboxes methods.
handleCheckboxList Method
This method is executed when any checkboxes are checked and accepts two parameters. The first parameter is an array of the selected items and the second parameter is the query.
checkboxes Method
This method provides the results shown in the rendered checkbox list on the frontend. It needs to return an array that has id, name, and url as keys. The url key should use the $this->getUrlFor() helper method to create a url for the id.
<?php
namespace Acme\MyModule\Filters;
use Aero\Admin\Filters\CheckboxListAdminFilter;
use Aero\Cart\Models\OrderStatus;
class OrderStatusStateAdminFilter extends CheckboxListAdminFilter
{
protected function handleCheckboxList(array $selected, $query)
{
$query->whereIn('state', $selected);
}
protected function checkboxes(): array
{
return OrderStatus::query()->distinct('state')->get()->map(function ($status) {
return [
'id' => $status->state,
'name' => ucwords(implode(' ', explode('_', $status->state))),
'url' => $this->getUrlFor($status->state),
];
})->toArray();
}
}