laraditz/model-filter
Flexible Eloquent model filtering for Laravel with operator support (eq, gte, etc.), AND/OR grouping, and relationship filters via dot notation. Add a Filterable trait and allowlist fields, optionally create filter classes for custom logic, and filter using request params under filters[].
=, >, <), and relationship filtering via dot notation (e.g., role.name). This aligns well with common API filtering needs.filters[] namespace (post-v2) suggests it’s optimized for API use cases where query parameters are passed as an array (e.g., ?filters[name]=John&filters[age]>30).Filterable trait is additive, requiring minimal changes to existing models. No core Laravel files are modified.make:filter command provides a structured way to define custom filter logic, reducing boilerplate.filters[] namespace shift could disrupt existing implementations if not accounted for during migration.with() or eager loading.Validator or API resources).LIKE, IN, NULL) supported out-of-the-box, or will custom methods be needed?admin fields to admins only)?where clauses, scopes) to identify candidates for replacement.filters[] namespace (v2 requirement).User) to test the trait and scaffolded filter class.UserFilter class with model-specific logic (e.g., scopeActive()).FormRequest or API resources).spatie/laravel-query-builder). Test in isolation.where clauses with filter trait usage in controllers/services.filters[] input.with()) for relationships to mitigate N+1 queries.filters[age] must be numeric).UserFilter), making them easier to maintain than scattered where clauses.filters[id][0]=1&filters[id][1]=2&...).filters[created_at][0]=1970-01-01&filters[created_at][1]=2030-01-01) could return massive datasets.?page=1) and size limits (?limit=100) by default.filters[non_existent_field]=value) may throw errors or return incorrect results.$filterable allowlist and handle unknown fields gracefully.filters[name]=John) is intuitive. Custom methods require understanding of Eloquent scopes.HttpTests or TestCase. Example:
public function test_user_filter_by_name()
{
$user = User::factory()->create(['name' => 'John']);
$response = $this->get('/users', ['filters[name]' => 'John']);
$response->assertJsonCount(1);
}
How can I help you explore Laravel packages today?