- What is pricecurrent/laravel-eloquent-filters and what problem does it solve?
- It is a Laravel package that adds advanced, reusable filtering capabilities to Eloquent models. Instead of scattering query-string conditionals across controllers and models, you define dedicated filter classes and map request parameters to them. This keeps search pages, APIs, admin lists, and reporting endpoints clean and testable. It is an application-layer utility rather than a platform-wide framework.
- How do I install laravel-eloquent-filters with Composer?
- Install it like any other Laravel package with a Composer require command for pricecurrent/laravel-eloquent-filters, then register the service provider if your Laravel version does not auto-discover it. Publish any provided configuration file if you want to customize defaults. After that, create your first filter class and attach it to a query. Check the repository README for the exact command and provider name for your version.
- Which Laravel and PHP versions does this package support?
- Support depends on the package's composer.json constraints and what its CI matrix actually tests, so verify both before committing. The project had a release in March 2025, which suggests reasonably current framework support, but that alone does not guarantee compatibility with every Laravel LTS branch. If your product spans multiple Laravel versions, require an explicit CI matrix and upgrade plan from the maintainer first.
- How do I create a filter class and apply it to an Eloquent query?
- You define a filter class that describes which query-string parameters it accepts and how each one modifies the underlying query builder. You then attach that filter to a model query, typically in a controller or dedicated query object, and it applies only the parameters present in the request. This keeps each filter small, reusable, and independently testable. Existing query scopes can usually be moved into filters incrementally.
- Can filters be driven directly from query-string parameters?
- Yes, the package is designed around request-driven filtering, so you map query-string keys to filter behavior rather than writing manual request checks. That makes it well suited to search pages, REST and JSON APIs, and admin tables where clients control the filters. You should still explicitly define and allowlist the accepted parameters so unexpected input is ignored. Authorization and tenant scoping remain your responsibility.
- Does it work with existing Eloquent scopes, policies, and pagination?
- Filters operate on the Eloquent query builder, so they generally compose with existing local scopes and pagination calls. Laravel policies apply to models and actions rather than to builder state, so you must still enforce authorization around the endpoint and around which fields are filterable. A short spike against your real endpoints is the safest way to confirm composition behavior. Consider wrapping the package behind a small internal convention layer so product code is not tightly coupled to its API.
- How do I prevent users from filtering on unauthorized or tenant-scoped columns?
- Treat the filter catalog as part of your API contract: define an explicit allowlist of filterable fields per endpoint and reject or ignore anything else. Apply tenant scoping to the base query before filters run so filters cannot widen the result set across tenants. Combine this with your existing policies and authorization checks at the controller or request layer. Never let raw request keys pass straight into column names.
- How does it compare with Spatie Query Builder or plain Eloquent query scopes?
- Native query scopes are the cheapest option when filtering is trivial or limited to a couple of endpoints. Spatie Query Builder is a mature, widely adopted alternative with a broader ecosystem footprint. This package is a lighter, filter-class-centric approach with 176 stars, so it should be treated as an emerging utility rather than a foundational dependency. Evaluate all three against your filter catalog, team familiarity, and maintenance expectations.
- Will dynamic filtering cause query performance problems?
- Dynamic filters can produce queries that do not match your indexes, especially with sorting, large OR groups, or filters on unindexed columns. Benchmark representative queries on production-sized data and add indexes for the fields you allow filtering and sorting on. Watch for N+1 issues and runaway result sets by keeping pagination mandatory. Measure query latency on a flagged pilot endpoint before expanding to other surfaces.
- How do I test filters, and what is the exit cost if the package is abandoned?
- Filter classes are plain PHP, so you can unit test each one against a query builder and assert the generated SQL or results, plus feature tests that compare old and new endpoint output. Wrap the package behind a small internal adapter or convention layer so filters can be replaced by native scopes or another library without touching every endpoint. Given the package's low adoption score, plan an owner, a documented upgrade policy, and an exit strategy before standardizing. Pilot on one low-risk internal endpoint behind a feature flag first.