Skip to main content

Eloquent Eager Loading Patterns

The N+1 query is the silent killer of Laravel apps. with(‘relationship’) eager-loads in one extra query; with(‘post.author’) chains across hops.For ‘select only what you need’ use …

April 6, 2026 PHP chris 1 min read Architecture

Article takeaway

The N+1 query is the silent killer of Laravel apps. with('relationship') eager-loads in one extra query; with('post.author') chains across hops.For 'select only what you need' use …

The N+1 query is the silent killer of Laravel apps. with('relationship') eager-loads in one extra query; with('post.author') chains across hops.

For ‘select only what you need’ use with(['posts:id,title']) — note that you must include the foreign key for the relationship to hydrate correctly.

Telescope or Debugbar’s query timeline will surface N+1 issues fast. Long term, enable strict mode globally via Model::preventLazyLoading() in non-production environments.

Share X / Twitter LinkedIn

Leave a comment

Related Posts