kobykorman/eloquentify
Eloquentify turns one custom SQL query with JSON-aggregated relations into fully hydrated nested Eloquent models, collapsing N+1 and R+1 round trips into a single query with zero configuration.
Architecture fit
Eloquentify is an additive, opt-in package: a single trait (EloquentifiesQueries) applied to a base or individual Eloquent model, plus raw SQL whose JSON-aggregated columns are named after existing relation methods. It does not replace Eloquent, does not introduce a service provider or facade surface, and does not require schema changes. Architecturally it sits between the query layer and the hydration layer, which is a clean seam for a Laravel codebase that already leans on Eloquent. The trade-off is explicit: you give up the query builder's composability in exchange for one round trip. That is a good fit for read-heavy, latency-sensitive endpoints and a poor fit for teams that have standardized on never writing raw SQL.
Integration feasibility
Installation is one Composer require plus one line of trait wiring. The real integration cost is authoring and maintaining per-relation JSON aggregation SQL, which is driver-specific (PostgreSQL json_agg/json_build_object, MySQL JSON_ARRAYAGG/JSON_OBJECT, SQLite json_group_array). The README strongly implies PostgreSQL as the primary target. For a team with SQL fluency this is a half-day spike to a working endpoint; for a team without it, this package converts an ORM problem into a database problem they may not be equipped to own.
Technical risk
$appends, date serialization, exists, dirty state, and the retrieved event. Any divergence produces subtle bugs rather than loud failures.Key questions
$appends, and timestamps handled post-hydration?BelongsToMany pivot data, MorphTo/MorphMany, and HasOneThrough supported?Stack fit Best fit is a Laravel 10/11/12 monolith or API service on PostgreSQL where the models and relation methods already exist and are correct. Secondary fit on MySQL 8+. Poor fit on older MySQL/MariaDB without JSON functions, or where a connection proxy, read replica, or ORM-adjacent package mangles JSON column types. Also a poor fit where tenant isolation depends on Eloquent global scopes.
Migration path No data migration and no schema change, so the migration is purely code-level and reversible. The cleanest pattern is to introduce Eloquentify behind a query object or repository method that returns standard Eloquent models, so controllers, API resources, and downstream consumers are untouched. This makes adoption per-endpoint rather than per-codebase, and lets each endpoint be rolled back by reverting one method.
Compatibility
Requires an audit of the base model and any existing traits that intercept reads. Watch specifically for tenancy packages, authorization packages that apply model scopes, and any custom hydration overrides. Model factories and RefreshDatabase are unaffected, but tests asserting query counts will need updating — that is arguably the point.
Sequencing
Maintenance The package's own surface area is small, so package upgrades should be cheap. The ongoing maintenance burden is the hand-written SQL living in application code — that is now first-class code requiring review, tests, and per-driver coverage. Vendor risk is the material concern: single maintainer, no dependents, early-stage adoption. Mitigate by pinning the version, watching the repository, and accepting that the fallback is a fork (permitted by MIT, and the trait is small enough to own if necessary).
Support There is effectively no external support channel at this maturity level. Internal capability is the support model: the team must be able to read and debug JSON aggregation SQL and understand Eloquent hydration internals. Budget for a designated owner and for onboarding material, otherwise the pattern will be used inconsistently and decay.
Scaling
The headline benefit is real: collapsing N+1 lazy loads and R+1 eager loads into a single round trip is a large win on high-latency links or remote/managed databases, where per-query overhead dominates. The cost shifts to the database and to PHP memory. JSON aggregation over large parent sets is CPU- and memory-intensive server-side, and returns one wide row per parent, so payloads grow quickly. Pagination needs deliberate design — the natural approach is to paginate parent IDs first and aggregate within that constrained set, because LIMIT on the outer query does not constrain the inner aggregation. Unbounded use on large tables is the primary scaling hazard.
Failure modes
SELECT list omits a column the model casts or appends.Ramp-up Installing and getting one endpoint working is a day's work for a Laravel developer. Using it safely is a different bar: SQL fluency, per-driver knowledge, and an understanding of how Eloquent hydrates and serializes models. Realistically one to two days for a senior engineer to spike and benchmark, and one to two weeks to productionize with conventions, differential tests, a documented usage boundary, and a named owner. The 20-star, zero-dependent profile means the team is an early adopter, not a fast follower — plan for that in the risk register rather than treating the package as infrastructure.
How can I help you explore Laravel packages today?