Laravel Bug Hunt Hard +35 XP
N+1 in Blade
This loads too many queries in the loop.
LaravelFind the bug
1
$posts = Post::all();2
// Blade: @foreach($posts as $post) {{ $post->author->name }} @endforeach The bug is on line 1
Select the correct fix
Show answer and explanation
Answer: Both A and C work
Eager loading with with() or lazy eager loading with load() prevents N+1 by loading all authors in a single additional query.
Hint: Eager load relations to avoid N+1 queries.
What this challenge tests
Bug Hunt in Laravel: n+1, eloquent, eager-loading.