Can't catch quiz questions ids
You could add the id of the question/answer as a key in the name attribute of the inputs.
@foreach($q->questions as $qu)
<div class="p-2">
question: <input type="text" name="q[{{ $qu->id }}][question]" value="{{ $qu->question }}">
</div>
@foreach($qu->answers as $a)
<input type="checkbox" name="a[{{ $a->id }}][correct]" value="{{ $a->correct }}" class="form-check-input {{ $a->correct !== 0 ? 'active" checked' : '"' }}>
answer: <input type="text" name="a[{{ $a->id }}][answer]" value="{{ $a->answer }}">
@endforeach
@endforeach
This would group the inputs a little bit.
q[1][question]
a[1][correct]
a[1][answer]
a[2][correct]
a[2][answer]
a[3][correct]
a[3][answer]
a[4][correct]
a[4][answer]
a[5][correct]
a[5][answer]
q[2][question]
...
foreach ($r->q as $key => $value) {
CourseQuestion::where('id', $key)->update([
'question' => $value['question'],
]);
}
foreach ($r->a as $key => $value) {
CourseAnswer::where('id', $key)->update([
'answer' => $value['answer'],
'correct' => $value['correct']
]);
}