Laravel与多个表的关系

I'm creating an online test portal.

The table structure is

  1. live_test (To collect the different data of the test) - {id, title, instructions, total_questions, is_published, per_question_mark, per_question_negative_mark, duration}
  2. questions (To store the questions) - {id, live_test_id, index, type, question, option_1, option_2, option_3, option_4, solution}
  3. live_test_user (To find whether the user has already given the test or not) - {id, user_id, total_mark}
  4. live_test_answers (To find out whether the user has given the right answer of the question or not - for later analytics) - {id, question_id, user_id, answer_given, is_correct}

This is working perfectly. I just want to know is there any relationship we can establish so that we can perform

$question->user->answer

or, something like,

$user->question->answer

To easily find that whether a user has given the correct answer for a particular question or not.

Each question will have only one entry in live_test_answers for each user.

You need to go through your live_test_answers table in order to get the answer and the question.

// For the example let's fetch the first answer the user gave
$answer = $user->answers()->first();
// Now let's fetch the question related to the answer
$question = $answer->question;

// Now you can check the answer for the question, something like
$isCorrect = $answer->answer == $question->answer;