Oct 5, 2021
0
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?
Please or to participate in this conversation.