liam-wiltshire/laravel-jit-loader
Laravel JIT Loader adds just-in-time relationship loading to Eloquent, helping eliminate N+1 queries without manually eager-loading every relation with with(). It loads relationships only when needed, keeping model access simple and query-efficient.
$jit property, roughly equivalent to Laravel's built-in protected $with. The real decision here is not "buy this package" but "do we standardize default eager-loading at the model layer (package, $with, or a base-model convention), or do we enforce explicit with() everywhere?" Framing it that way keeps the team honest about the tradeoff.with() calls are scattered across dozens of controllers, without touching call sites. This supports "incremental modernization" over "big-bang refactor" as a roadmap strategy.Adopt when most of the following hold:
with() and Laravel's lazy-loading prevention.Look elsewhere (or just use built-ins) when:
$with property already covers you. It does effectively the same job with zero third-party surface area. If the only differentiator you can articulate is "declared once," you may not need the package at all. This is the honest default answer for most teams.Model::preventLazyLoading() in non-production plus CI query-count assertions; those catch regressions rather than papering over them.For executives: This is a small, MIT-licensed utility that reduces database load and page latency by automatically pre-loading related records that would otherwise be fetched one-by-one. The cost is near zero — no licensing, no infrastructure, roughly an hour of engineering to trial on one or two models — and the downside is bounded because it's a one-line removal per model if it doesn't pay off. The caveat I'd flag up front: it's a 2020-era package with a single maintainer, so I'd position this as "adopt the pattern, own the code" rather than "add a dependency." I'd recommend a timeboxed pilot on our two slowest list endpoints and a measured query-count comparison before any broader rollout.
For engineering: One trait, one $jit property per model; relations are eager-loaded just in time, and it coexists cleanly with explicit with() and lazy-loading prevention. It removes the "remember to add with() here" failure mode that review process alone hasn't solved. Two things to settle together before we commit: (1) verify it works on our current Laravel/PHP versions, and (2) confirm the delta versus protected $with is worth carrying third-party code — if it isn't, we adopt the pattern in our base model instead and keep the dependency count flat. Either way, the decision is reversible per model, so the cost of being wrong is low and the cost of not measuring is higher.
How can I help you explore Laravel packages today?