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[].
/api/users?filters[name]=John&filters[age][gt]=25) without manual query-building logic.=, >, <, LIKE, IN, OR/AND grouping) while maintaining flexibility for edge cases.Adopt if:
user.role.name = 'admin') or operator support (age[gt]=18).Look elsewhere if:
whereRaw).Query Builder or Filament for admin panels)."This package lets us ship search/filter features 10x faster by standardizing how our backend handles queries like ‘find users aged 25–35 with role X.’ Instead of writing custom SQL or Eloquent scopes for every model, we’ll use a single, reusable trait—reducing dev time and tech debt. For example, an admin panel for user management could support filters like name=John&status[active]=true out of the box, with room to add advanced logic later. It’s lightweight (MIT-licensed), Laravel-native, and future-proofs our API for client-side filtering needs."
*"Pros:
where() chains with a $filterable allowlist (e.g., ['name', 'role.id']).=, >, <, LIKE, IN, etc., with OR/AND grouping via filters[] array syntax.user.role.name) enables nested filtering without manual joins.php artisan make:filter generates a clean class for custom logic (e.g., UserFilter::apply($query)).Trade-offs:
filters[] namespace convention (v2 breaking change).Use Case Example:
// Before: Manual query in a controller
$users = User::where('name', 'like', '%John%')
->whereHas('role', fn($q) => $q->where('name', 'admin'))
->get();
// After: One-liner with filter trait
$users = User::filter(request('filters'))->get();
Ask: Should we prototype this for [X feature] to validate the ROI?"*
How can I help you explore Laravel packages today?