Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eheins's avatar
Level 18

Query calculations with child and grandchild relationships

I have three models; Quiz, Question and Answer. All the necessary relations are set. A Quiz can have one ore more Questions, and each Question has one or more multiple-choice Answers (Also the vice versa relations are set). For each Answer of a Question different points are given. Now for a Specific Quiz I want to query the max possible points possible. So the sum of the Answers with the highest score for all Questions in a Quiz.

I'm not sure how to manage this in Eloquent. Is this possible in one Query to minimize the number of queries?

0 likes
0 replies

Please or to participate in this conversation.