Exemple #1
0
 /**
  * @param $inputs
  */
 public function store($inputs)
 {
     $answersLabels = $inputs['answerLabel'];
     $answers = [];
     foreach ($answersLabels as $key => $answersLabel) {
         //Creating Answer object
         $answerEntity = new Answer();
         $answerEntity->setAttribute('label', $answersLabel);
         if ($key == $inputs['answerChecked']) {
             $answerEntity->setAttribute('correct', true);
         } else {
             $answerEntity->setAttribute('correct', false);
         }
         $answers[] = $answerEntity;
     }
     //Insert the question
     $question = new Question();
     $question->fill($inputs);
     $question->save();
     //Attach this question to one or several quizzs
     if (isset($inputs['quizz'])) {
         $question->quizzs()->attach($inputs['quizz']);
     }
     //Insert all the answers to this question
     $question->answers()->saveMany($answers);
 }