Weave 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

QueryBuilderParser is a Laravel/PHP package that converts jQuery QueryBuilder rules into safe SQL or MongoDB queries using a whitelist of allowed fields. It integrates with Laravel's query builder and jenssegers/mongodb for filtering and search.

View on GitHub
Deep Wiki
Context7

QueryBuilderParser parses jQuery QueryBuilder rules into executable Laravel query-builder queries. Primarily built for Laravel, it also works outside Laravel via Illuminate/Database, and supports MongoDB (through jenssegers/mongodb) by generating equivalent $regex/$and queries.

  • Parses QueryBuilder JSON rules directly into Illuminate\Database queries
  • Whitelist allowed columns to control which fields can be filtered
  • Generates SQL (LIKE, AND) or MongoDB queries automatically
  • Integrates with Laravel, jQuery Datatables, and MongoDB collections
  • Simple API: instantiate, call parse(), then get()
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource