Hi,
I'm having a high number of SQL queries when I enable pagination in my view. I basically have courses, reviews for theses courses, and students writing them, and the problem happens when I want do display every written for a particular course.
When pagination is not enabled, I have a constant number of queries.
$course = Course::with('reviews.student')->findOrFail($id);
Makes the following SQL queries (bigger image here)
But when I pass $course->reviews()->paginate($nbPerPage)
to my view (instead of $course->reviews
), there are much more queries (and the number actually grows with the number of reviews) : (bigger image here)
You can see there are lots of SQL queries, as well as duplicates. How to fix this?
Thank you very much! Christophe
You probably need to eager load
$course->reviews()->with('student')->paginate(10);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community