Laravel Query Builder is a PHP package that builds Eloquent queries from API requests.
The package solves the problem of translating API request parameters into database queries by providing a declarative syntax for filtering, sorting, including relationships, and selecting fields. Rather than manually parsing query strings and constructing Eloquent queries, developers define which filters, sorts, includes, and fields are allowed, then pass the request to the query builder. It supports filtering with partial matches, exact matches, and custom scopes; grouping filters with OR and AND operators; including nested relationships and relationship counts; sorting in multiple directions; and selecting specific fields per resource.
Teams building REST or JSON:API endpoints should adopt this tool when they need to expose query capabilities safely without manually validating and constructing each query variant. It works well with existing Eloquent queries, allowing you to apply additional constraints before passing the query to the builder. The package is particularly suited to projects that want to follow JSON:API conventions for filtering and sorting. The documentation distinguishes between different filter types and provides examples of custom implementations, suggesting it handles both simple and specialized query requirements.
The project maintains a comprehensive test suite and publishes a changelog documenting changes. Documentation is hosted separately and kept current with the package versions. The team provides a security contact for vulnerability reports rather than using the public issue tracker, indicating attention to security concerns. Contributing guidelines are established, and the project accepts community contributions.