A Laravel package for filtering Eloquent models and their relationships using expressive, convention-based methods.
EloquentFilter is a Laravel package that simplifies filtering Eloquent models based on HTTP request parameters. It replaces verbose conditional query logic in controllers with a single `filter()` method call, mapping input keys to predefined filter methods in dedicated classes. This approach centralizes filtering logic, making it reusable and maintainable.
Laravel developers building applications with complex filtering needs, especially those working on RESTful APIs or admin panels where users filter data via query parameters.
Developers choose EloquentFilter because it drastically reduces boilerplate code in controllers, provides a consistent convention-based API, and supports advanced features like relationship filtering and dynamic filter switching without sacrificing flexibility.
An Eloquent Way To Filter Laravel Models And Their Relationships
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically maps request keys like 'company_id' to camel-cased filter methods (e.g., company()), eliminating repetitive conditional code as shown in the README's before-and-after comparison.
Supports filtering through nested relationships using $relations arrays or the related() method, enabling complex queries without multiple whereHas() calls, as detailed in the relationships section.
Allows runtime filter selection based on conditions like user roles, facilitating role-specific data views without code duplication, demonstrated in the Dynamic Filters example.
Provides paginateFilter() and simplePaginateFilter() methods that preserve query strings, avoiding the need for manual appends() in views, as mentioned in the pagination support section.
Requires creating a separate filter class for each model, leading to increased file count and maintenance overhead in applications with many models, which the README acknowledges as a standard setup.
Setting up relationships, blacklists, and dynamic filters involves multiple steps (e.g., defining $relations arrays, service provider registration), which can be cumbersome and error-prone for newcomers.
Only basic helper methods like whereLike are provided; advanced filtering logic must be custom-coded in each filter class, lacking out-of-the-box support for common patterns like date ranges or sorting.