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+.
allowedFilters() method enforces a clear contract for filter definitions, improving maintainability and reducing runtime errors from invalid queries.?name=TV&price[gt]=100) to Eloquent queries, ideal for APIs or search-heavy applications.use Filterable trait and allowedFilters() method). No database migrations or schema changes needed.$or/$and conditions out-of-the-box, enabling complex filtering without manual query chaining.JSON_LENGTH rely on database-specific JSON functions (e.g., PostgreSQL’s json_length). Compatibility must be validated across target databases.allowedFilters(), runtime validation of incoming filter values (e.g., type safety) is not enforced by the package.json_length)?$eq, $gt, $like, etc.) cover 80% of use cases, or will custom filters need to be extended?target or value).where clauses) coexist with the new filtering system? Will a hybrid approach be necessary?GET /products?category=$eq:electronics) or GraphQL resolvers.Product or User) to validate the package’s fit.where clauses in controllers with Model::filter($request->all()).IsFilterable and use the Filterable trait.$request->query() or $request->all()). May need middleware to normalize input (e.g., flatten nested arrays).JSON_LENGTH) on the target database to ensure compatibility.composer require indexzer0/eloquent-filtering).php artisan eloquent-filtering:install).config/app.php to bind the package’s service provider.use Filterable and allowedFilters() to target models.Filter::field('name', [FilterType::EQUAL])).Model::filter($request->query()).public function index(Request $request) {
return Product::filter($request->query())->get();
}
allowedFilters() definitions.$eq, $like) simplify onboarding.allowedFilters() definitions.toRawSql() to inspect generated queries.DB::enableQueryLog()) for complex filters.name, price).->paginate()) for large datasets.Product::filter($request->query())->remember(60)).$or/$and conditions).target or type) may cause silent failures or SQL errors.Validator.json_length) will fail on incompatible databases.target values could enable SQL injection (e.g., target="1 OR 1=1").allowedFilters() and sanitize inputs.FilterType constants.allowedFilters() definitions.How can I help you explore Laravel packages today?