Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Eager Loading with load() and $with

Premium
1:54

In the previous lessons, we discussed how to solve N+1 query problems using eager loading with the with() method directly in your query. However, there are situations where you might need alternative approaches to eager loading. This lesson covers those techniques.

Let's return to our original example of viewing posts with their authors. As we've seen, without eager loading, this produces 31 queries - one for posts and 30 separate queries for users.


Loading Relationships After Initial Query

Sometimes you might receive an Eloquent collection from another part of your application, perhaps from code written by another developer, and you don't have direct access to modify the original query. In these situations, you can load relationships dynamically after...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…