Vivek Mistry 👋

I’m a Certified Senior Laravel Developer with 8+ years of experience , specializing in building robust APIs and admin panels, frontend templates converting them into fully functional web applications.

Book A Call
  • 10 Mar, 2026
  • 39 Views
  • Load relationships only when they are not already loaded.

Avoid N+1 Query Problems in Laravel Using loadMissing()

The Hidden Problem: Duplicate Relationship Queries


In Laravel applications, relationships are often loaded in multiple places.

Example:

  • Controller loads user
  • Later, a service loads user->roles
  • A resource loads it again

This can lead to extra database queries.


The Smart Solution: loadMissing()

Laravel provides loadMissing() to load a relationship only if it hasn't been loaded already.

Example:

$user->loadMissing('roles');

If roles is already loaded → nothing happens.

If not → Laravel loads it.

Why This Is Useful

loadMissing() helps you:

  • Avoid duplicate queries
  • Write reusable services
  • Prevent N+1 query problems
  • Keep performance predictable


Share: