Laravel list page runs 101 queries for 100 posts
Asked by Oskar Brandt · 557 views · 3 replies
Our blog index got slow, so I turned on the query log. One query for the posts, then one more for every single post. This is the controller and the loop in the view:
$posts = Post::latest()->take(100)->get();
// in the Blade view
@foreach ($posts as $post)
{{ $post->title }} by {{ $post->author->name }}
({{ $post->comments->count() }} comments)
@endforeach
Where are the extra queries coming from? I only call get() once.