cool
return records from multiple related tables using eloquent
i'm trying return from a eloquent query data from the following tables:
users, exams, questions, answers, exam_question (pivot), essays, users_answers, users_essays.
so, the exam is the main here, i want select the exam that the user finished in my app. each exam has (n) questions and the questions had the answers (5 max), the user can select only one answer (input radio at the form), if selected, the answer is stored in users_answers table, essay in users_essay table, users_answers and users_essays has the id of the user and id of the question and answer table.
this is my schema (not sure if is ok): https://dbdiagram.io/d/5ec01ae339d18f5553ff4d9d
tried several ways here, but i ended a bit stuck with this, i made 3 nested for loops exams -> questions -> answers but it not work since i must retrieve the users_answers and users_essays too at same query. i want retrieve it like:
[exam] => [ question1 => user_answer, question2 => user_answer ];
from a specific user.
ps: my answers table has one field called: is_correct (boolean) so... i can check if the answers is right or not in my view.
Please or to participate in this conversation.