I am trying to save data into QuestionOption table and facing issue of recursion detected. I have been searching everywhere but could find any answer to this issue. Following is the where i am trying to save data into DB.
$question = new Question();
$question->type = $request->type;
$question->optional = $request->optional;
$question->question = $request->question;
$question->status = $request->status;
$question->save(); ////// WORKS PERFECTLY TILL THIS LINE
if ($request->type == 'choice') {
foreach ($request->options as $key => $option) {
$option = new QuestionOption(); ////////HERE I AM FACING THAT ERROR
$option->question_id = $question->id;
$option->option = $option;
$option->status = 'active';
$option->save();
}
}
Following is the model I am using for QuestionOption, i could not find anything wrong with this.
class QuestionOption extends Model
{
protected $dates = [
'created_at',
'updated_at',
];
protected $fillable = [
'question_id',
'option',
'status',
'created_at',
'updated_at',
];
}
Please guide me through this. Thanks!