Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Query Builder Parser

Query Builder Parser Laravel Package

timgws/query-builder-parser

Parse jQuery QueryBuilder rules into safe Laravel query builder constraints. Whitelist allowed fields, then generate SQL (Illuminate/Database) or MongoDB queries (via jenssegers/mongodb). Works well with tools like jQuery DataTables for advanced filtering.

View on GitHub
Deep Wiki
Context7

A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.

Frequently asked questions about Query Builder Parser
How do I integrate QueryBuilderParser with jQuery QueryBuilder in a Laravel app?
First, include the jQuery QueryBuilder plugin in your frontend. Then, in your Laravel controller, instantiate `QueryBuilderParser` with an array of allowed fields (e.g., `['name', 'email']`). Pass the JSON rules from QueryBuilder to `parse()` along with your database query builder (Eloquent or QueryBuilder), then execute the generated query. Example: `$query = $qbp->parse($request->querybuilder, DB::table('users'))->get();`
Does QueryBuilderParser support MongoDB queries?
Yes, but you’ll need to install the `jenssegers/mongodb` package separately. QueryBuilderParser generates MongoDB queries using the same JSON rules, converting them to `$and`/`$regex` syntax. Example: `$query = $qbp->parse($rules, DB::collection('data'));`
What Laravel versions does QueryBuilderParser support?
The package officially supports Laravel 5.5 through 13. For older versions (e.g., 5.5), minor adjustments may be needed, such as Carbon compatibility fixes. Always test thoroughly if using versions outside the latest stable range.
Can I use QueryBuilderParser with non-jQuery QueryBuilder UIs like AG Grid or Tabulator?
The package is designed for jQuery QueryBuilder’s JSON rule format. For other UIs, you’ll need to manually adapt their rule output to match the expected format or pre-process it before passing it to `QueryBuilderParser`. Check the UI’s documentation for JSON output examples.
How does QueryBuilderParser prevent SQL injection?
The package enforces a whitelist of allowed fields during initialization, ensuring only those columns are queried. It also uses Laravel’s built-in query builder, which automatically escapes parameters. However, always validate input rules on the frontend for an extra layer of security.
What if my queries require complex joins or subqueries?
QueryBuilderParser supports basic joins via the `JoinSupportingQueryBuilderParser` extension. For advanced SQL features like CTEs or window functions, you’ll need to manually extend the parser or handle those queries separately in your application logic.
Is there a performance impact when using QueryBuilderParser?
No significant overhead. The parser generates standard Laravel queries, which are executed efficiently. Benchmarking shows minimal runtime difference compared to manually building queries, as it avoids redundant parsing logic.
How do I test QueryBuilderParser in my Laravel application?
Mock the frontend rules (e.g., `$rules = ['rules'] => [['field' => 'name', 'operator' => 'contains', 'value' => 'tim']]`) and test the generated query using Laravel’s `DB::expectsQuery()` or `Assert::assertSql()` in PHPUnit. Verify both SQL and MongoDB outputs match expectations.
Are there alternatives to QueryBuilderParser for Laravel?
For SQL queries, consider `spatie/laravel-query-builder` or `beberlei/doctrine-extensions` (for Doctrine). For MongoDB, `jenssegers/mongodb` offers native query building. However, QueryBuilderParser uniquely bridges jQuery QueryBuilder with Laravel’s query builder, making it ideal for dynamic frontend filtering.
How do I deploy QueryBuilderParser in production?
Ensure your frontend sends only whitelisted fields to avoid runtime errors. Cache the parsed queries if reused (e.g., in admin panels). Monitor query logs for unexpected patterns, especially if using MongoDB, where regex queries can impact performance. Always test with production-like data volumes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony