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

Wakanda's avatar
Level 10

Exam web app architecture help

Hi, devs, A saas web app exists that high XUL students can access to get exam preparatory material and past exam papers.

The web app now needs to be modernized and make it more interactive, adding functionality to take an exam of the past exam paper online with a timer and give a score at the end of the exam and also show your answers against the correct and the end of an exam.

Processing this in my head, I going to need

1.Exam Model [has many questions]

2. Questions Model [a question has many answers and belongs to Exam]

3. Answers Model [an answer belong to a question and also has a boolean of correct and incorrect]

4 . A user model [a user has many exams, meaning a user can take many exams]

5. Pivot table to store whether a user has taken an exam

Hoping what I have is correct the dilemma comes when trying to figure out the best way to store a users score and also highlighting user answers and correct answers at the end of the exam

Should I have a score/results table and also the answers table that links a user's answers to an exam?

0 likes
7 replies
automica's avatar

Are you allowed to crowd source your answers if it’s an exam question?

Wakanda's avatar
Level 10

@automica its an exam preparatory app so yes its allowed & the question I asked is not an exam question its an app I own that I want to improve

automica's avatar
automica
Best Answer
Level 54

Ok. So for your answers, how do you get access to answers submitted by a specific user?

You’ll need a table with

  • user_id
  • answer_id

You might to add dates too, so you can track when answer was submitted

You may also want to record whether this is the correct answer here, although you can probably get that via relationship on answers table

  • Answer belongsToMany User
  • Answer belongsTo Question
  • Question belongsTo User
Wakanda's avatar
Level 10

@automica Thanks for your reply to answer your question how do you get access to answers submitted by a specific user?

At this stage as the app as it exists is more of a simple app that a user pays to download certain exam preparatory material

And you mentioned having a table with user_id and answer_id and a follow-up question is how do I also keep track of the question when I want to display the question and the answer provided by a user at the end of an exam? Do I also have to add a question_id in addition to user_id and answer_id

automica's avatar

You already have a relationship between Question and Answer so you should be able to get the Question for an Answer that way

foreach($user->answers as $answer) 
{

$answer->question->title; // display question for specific answer 

}
1 like

Please or to participate in this conversation.