I have a quiz. The quiz has 10 questions. First time I saved 7 questions of the quiz using the below code.In the second case I wanted to save the quiz questions again. But in this case the data is being duplicated. I want the question that have been saved once not to be saved in the second time.
foreach($request->input('questions', []) as $key => $question){
QuizSessionAnswer::create([
'session_id'=> $sessionId,
'question_id'=> $question,
'selected_choice_id'=> $request->input('choice.'.$question),
'created_by_id'=> auth()->user()->id,
]);
}
How can I solve the problem?
question from:
https://stackoverflow.com/questions/65850602/how-to-control-data-repeatation-in-laravel 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…