zing/laravel-query-builder
A Laravel package for building cleaner, reusable Eloquent queries with composable filters, sorting, and relationship helpers—keeping controllers and models concise while making complex database queries easier to organize and maintain.
RequestFilter/QueryFilter base class in-house. That is a two-to-five-day build plus permanent ownership of edge cases (invalid sort keys, unknown filter names, injection via ?sort=, pagination caps). Using a package converts that into a dependency review — cheap, and reversible if encapsulated.filter[x]=, sort=-created_at, per_page=) is a product decision, not just a technical one: it's what your API docs, SDKs and partner integrations will be written against. Adopting one library is the cheapest way to enforce consistency.Consider it when all of the following hold:
composer.json — not the README. As of 3.4.0 the package declares support for Laravel 13 and PHP 8.5, plus PHPUnit 12, so it is unlikely to be the constraint that blocks a stack upgrade.Treat the following as blockers or strong cautions:
spatie/laravel-query-builder is the default answer with a large user base, documentation and a track record. Choosing this package requires a specific, articulable reason the incumbent does not fit — not merely "it's smaller." Note that the API surface here closely mirrors the incumbent's; confirm during the spike whether it is a fork/tracking implementation, because if so, switching cost in either direction is low and the encapsulation argument below becomes very cheap insurance.Look elsewhere if: you need search relevance (Scout), you need a full API specification/design layer (OpenAPI tooling), you want first-party support (Laravel's own resource/filter patterns), or your team's policy requires dependencies above a minimum adoption threshold — most enterprise dependency policies would flag near-zero dependents out of the gate, and 3.4.0 does not move that number.
Practical mitigation if adopted: wrap it behind an internal QueryBuilder interface or base repository so the library is a swappable implementation detail, pin the version in composer.json (^3.4), and add contract tests on your query-parameter grammar so a future migration is a swap, not a rewrite.
To executives (one paragraph). We have a recurring, low-differentiation engineering task: turning URL parameters into database queries for every list screen and API collection we ship. This MIT-licensed Laravel package handles that for us, worth roughly a few engineering days per surface and, more importantly, removing a class of recurring security bugs (unvalidated sort/filter input). The latest release keeps pace with current Laravel and PHP versions, so it won't become the reason we can't upgrade. The remaining cost is a dependency we don't control, so we'd isolate it behind our own interface. Recommendation: adopt tactically behind an abstraction, not as a platform standard.
To engineering leadership. It is a small, single-purpose library, actively released, MIT-licensed — low legal and cost risk. Release 3.4.0 is a genuine improvement to the risk profile: it adds Laravel 13 and PHP 8.5 support and PHPUnit 12 compatibility, which means the framework-upgrade scenario that most threatens single-maintainer dependencies has already been handled once. Treat that as one positive data point, not a cleared risk — the release is otherwise dependency bumps, and the project still reads as one maintainer with no third-party users. Ask for: a thin internal adapter, ^3.4 pinning, and contract tests on our query grammar. If the team cannot commit to that encapsulation, use the established package instead — the switching cost later will exceed the days saved now.
To the engineering team. Use it if it earns its place in a spike: build one representative endpoint (filters + multi-column sort + pagination + an injection attempt on ?sort=) and compare against the incumbent on lines of code and clarity. Also use the spike to confirm whether the API mirrors spatie/laravel-query-builder — if it does, migration in either direction is a small diff and the dependency choice is genuinely low-stakes once abstracted. Ship it only with an allow-list of filterable/sortable fields — never pass user input straight to the query builder — and a hard cap on per_page. If the spike doesn't show a clear win, the answer is the boring, well-documented option.
How can I help you explore Laravel packages today?