indexzer0/eloquent-filtering
Define allowed filters on your Eloquent models and apply them from simple arrays or request data—no custom query logic. Supports complex, type-based filtering for APIs and dashboards on Laravel 10+ / PHP 8.2+.
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?