You can do it using a custom filter:
https://spatie.be/docs/laravel-query-builder/v5/features/filtering#content-custom-filters
class InitializedFilter implements Filter
{
public function __invoke(Builder $query, $value, string $property)
{
match($property) {
'initialized_at_between' => $query->whereBetween('initialized_at', ......),
'initialized_at_before' => $query->where('initialized_at', '<=', ......),
'initialized_at_after' => $query->where('initialized_at', '>=', ....),
};
}
}
Then in your controller you set allowedFilters like this:
->allowedFilters(
....
AllowedFilter::custom('initialized_at_between', new InitializedFilter()),
AllowedFilter::custom('initialized_at_before', new InitializedFilter()),
AllowedFilter::custom('initialized_at_after', new InitializedFilter()),
)
The magic happens matching the parameter $name on the method AllowedFilter::custom() and the parameter $property of the Filter class