indexzer0/eloquent-filtering
Filter Laravel Eloquent models using simple arrays and request data—no custom query spaghetti. Define allowed filters on your models, support complex search, and keep queries readable, maintainable, and easy to extend for APIs and dashboards.
You can define your own validation rules, messages, and attributes for any AllowedType.
MalformedFilterFormatException is thrown.MalformedFilterFormatException extends Laravels ValidationException.
class Order extends Model implements IsFilterable
{
use Filterable;
public function allowedFilters(): AllowedFilterList
{
return Filter::only(
Filter::field('status', [
FilterType::EQUAL->withValidation([
'value' => [Rule::enum(OrderStatus::class)],
], [
'enum' => 'The selected :attribute is invalid.',
], [
'value' => 'status value',
]),
FilterType::IN->withValidation([
'value.*' => [Rule::enum(OrderStatus::class)]
])
]),
Filter::field('paid_date', [
FilterType::BETWEEN->withValidation([
'value.0' => ['date', 'before:value.1'],
'value.1' => ['date', 'after:value.0'],
])
]),
Filter::field('created_at', [
new AllowedType('$yourCustomFilterType')->withValidation([
'value' => [new YourCustomRule()],
])
]),
);
}
}
How can I help you explore Laravel packages today?