BuildBot

Laravel in a Container

Relationships & queries

Lesson 4 of 4

Connect tables with hasMany/belongsTo, then build queries fluently — and avoid the N+1 trap.

What you'll learn

  • Define a one-to-many relationship in Eloquent
  • Build queries with the fluent builder
  • Recognize and fix the N+1 query problem with eager loading
Members only

A free account unlocks this lesson and every other one.

Runnable challenges, knowledge checks, and progress that syncs across your devices. No card needed.

Not sure yet? Try the free lesson first: The Dockerized setup