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 alias your target fields and relations if you don't wish to expose database field names and relationship method names to your frontend.
The below example:
name and uses first_name in the database query.documents and uses files as the relationship method name.Person::filter([
[
'type' => '$eq',
'target' => 'name',
'value' => 'Taylor',
],
[
'type' => '$has',
'target' => 'documents',
'value' => [],
],
], Filter::only(
Filter::field(Target::alias('name', 'first_name'), [FilterType::EQUAL]),
Filter::relation(Target::alias('documents', 'files'), [FilterType::HAS])
));
How can I help you explore Laravel packages today?