In my Laravel application, I have three models: Lesson, Quiz, and Answer (which should have been named Option). The relationships are set up so that each Lesson has Quizzes, and each Quiz has Answers. In a Blade file, I have access to a $lesson instance. My goal is to send both $lesson->quizzes and $quiz->answers from Blade to a VueJS method. Currently, I am only able to send the quizzes:
<modal-button color="success" size="small" icon="eye" header="View Quiz" btntxt="View Quiz" @showmodal="onShowViewQuizModal({{ $lesson->quizzes }})">
@include('partials.quizform')
</modal-button>
I receive the sent quizzes in my VueJS method and assign the array of objects to a VueJS data property:
onShowViewQuizModal(quizzes){
this.quizzes = quizzes;
}
Within the quizform partial, I am attempting to display this nested data structure. My idea for accomplishing this is as follows:
<div v-for="quiz in quizzes">
<p>@{{ quiz.title }}</p>
<div v-for="answer in quiz.answers">
<p>@{{ answer.title }}</p>
</div>
</div>
Currently, only the outer v-for loop works, while the inner v-for loop does not because quiz.answers is likely undefined.
I hope you understand the issue, as it's common and many may have encountered it before. What would be the best way to handle this situation?