Performance: Eager loading (with)
HIGH IMPACT
Eager loading reduces the number of database queries, improving page load speed and interaction responsiveness.
$posts = Post::with('author')->get(); foreach ($posts as $post) { echo $post->author->name; }
foreach ($posts as $post) {
echo $post->author->name;
}| Pattern | Database Queries | Network Requests | Server Response Time | Verdict |
|---|---|---|---|---|
| Lazy loading (accessing relations inside loop) | N+1 queries | Multiple | High | [X] Bad |
| Eager loading with 'with' method | 2 queries | Few | Low | [OK] Good |