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.
By default, all filters are disallowed.
You can define allowed filters in two ways:
use IndexZer0\EloquentFiltering\Contracts\IsFilterable;
use IndexZer0\EloquentFiltering\Filter\Filterable\Filter;
use IndexZer0\EloquentFiltering\Filter\Traits\Filterable;
use IndexZer0\EloquentFiltering\Filter\Contracts\AllowedFilterList;
use IndexZer0\EloquentFiltering\Filter\FilterType;
class Product extends Model implements IsFilterable
{
use Filterable;
public function allowedFilters(): AllowedFilterList
{
return Filter::only(
Filter::field('name', [FilterType::EQUAL, FilterType::LIKE]),
Filter::relation(
'manufacturer',
[FilterType::HAS, FilterType::DOESNT_HAS],
Filter::only(
Filter::field('name', [FilterType::LIKE])
)
)
);
}
public function manufacturer(): BelongsTo
{
return $this->belongsTo(Manufacturer::class);
}
}
::filter()Product::filter(
$filters,
Filter::only(
Filter::field('name', [FilterType::EQUAL, FilterType::LIKE]),
Filter::relation(
'manufacturer',
[FilterType::HAS, FilterType::DOESNT_HAS],
Filter::only(
Filter::field('name', [FilterType::LIKE])
)
)
)
)->get();
How can I help you explore Laravel packages today?