makinacorpus/query-builder
A fluent SQL query builder for PHP that lets you construct complex SELECT, INSERT, UPDATE, and DELETE queries programmatically through a clean, chainable API. Lightweight and framework-agnostic, it integrates easily into Laravel or any PHP application.
Architecture fit. makinacorpus/query-builder is a standalone, driver-agnostic SQL builder: queries are expressed as structured data (selects, joins, where clauses) and compiled to a dialect-specific SQL string. This is conceptually adjacent to — not a replacement for — Laravel's Illuminate\Database\Query\Builder and Eloquent. The only defensible fit inside a Laravel codebase is as a query-definition/serialization layer (e.g. saved reports, user-defined filters, query templates persisted as JSON) that compiles to SQL and hands off to Laravel's connection for execution. Using it as the primary data-access layer would create a second, parallel query abstraction alongside Eloquent, doubling the mental model for every developer on the team.
Integration feasibility. Technically low-friction: MIT-licensed, Composer-installable, no framework coupling implied, and usable as a leaf dependency behind an internal adapter. Practically, expect to write the Laravel glue yourself — there is no evidence of a service provider, facade, config publishing, or Laravel version constraints. Execution, connection pooling, transactions, logging, and query timing all remain Laravel's responsibility.
Technical risk. High relative to value:
JSONB operators, LATERAL joins, and upserts — precisely the features reporting queries tend to need.Key questions.
dev-main?composer.json constraints?Stack fit. Poor as a core ORM replacement, acceptable as a narrow component. The natural boundary is: our application owns the query model (a validated DTO), this package owns compilation, and Laravel's DB facade owns execution. Do not let it manage connections, transactions, or result hydration.
Migration path. There is no migration — nothing depends on it today, so this is greenfield adoption, not a swap. Recommended path:
QueryCompiler interface with compile(QueryDefinition): array{sql, bindings}. No application code imports the vendor namespace directly. This makes the package swappable — a fork, a replacement, or a return to Laravel's builder — without touching call sites.Compatibility. Verify PSR-4 autoloading, PHP constraint, and absence of conflicting transitive dependencies before locking. Register it as a singleton in a service provider we own; do not rely on package discovery. Pin the version exactly (composer require with a fixed constraint) and commit composer.lock — with 0 dependents, semver discipline is unproven and a minor bump could break compilation output.
Sequencing. Security review of escaping/binding → spike → adapter interface → single-surface pilot → evaluate → fork-or-adopt decision. Front-load the security review; it is the only step that can kill the initiative outright.
Maintenance. Assume we own it. Budget for periodic fork-and-patch, dependency-bump verification, and dialect updates when we upgrade PostgreSQL or MySQL. With one small team and no upstream SLA, this is a recurring, unbounded line item — modest in absolute terms but non-zero forever.
Support. No commercial support, no vendor contact path, no defined security disclosure process. Internal knowledge will concentrate in whoever runs the spike. Mitigate with an ADR, a short internal README, and the adapter interface so the package is not load-bearing for architecture.
Scaling. Negligible runtime footprint — compilation is in-process string assembly, dwarfed by database execution time. The scaling concern is organisational, not technical: the abstraction will resist supporting new database features, and every new dialect need becomes our problem.
Failure modes.
Ramp-up. The API surface is small; a mid-level PHP developer should be productive in 2–3 days. The real ramp-up cost is the conceptual one: teaching the team when to use this builder versus Eloquent, and why two query layers exist. That ambiguity is a persistent tax on onboarding and code review unless the boundary is documented and enforced by the adapter interface.
Recommendation. Proceed to a time-boxed spike only, gated on the security review and a demonstrated win over a ~200-line in-house query DTO plus Laravel's builder. Given 7 stars, 0 dependents, and a single-organisation maintainer, this should not become a platform dependency without a credible fork-and-own commitment.
How can I help you explore Laravel packages today?