Skip to content

Instantly share code, notes, and snippets.

@Cyberiaaxis
Created November 12, 2017 13:35
Show Gist options
  • Save Cyberiaaxis/aaeecf1a5909b6a5f2a1bf8edb2ada3e to your computer and use it in GitHub Desktop.
Save Cyberiaaxis/aaeecf1a5909b6a5f2a1bf8edb2ada3e to your computer and use it in GitHub Desktop.
public function store(Request $request)
{
$ques = new Question();
$ques->question_text = $request['question_text'];
$ques->code_snippet = $request['code_snippet'];
$ques->answer_explanation = $request['answer_explanation'];
$ques->more_info_link = $request['more_info_link'];
$ques->category_id = $request['category_id'];
$ques->topic_id = $request['topic_id'];
dd($ques->save());
// "option1" => "ans1"
// "option2" => "ans2"
// "option3" => "ans3"
// "option4" => "ans4"
// "option5" => "ans5"
// "correct" => "option4"
// $question = Question::create($request->all());
foreach ($request as $key => $value) {
if(strpos($key, 'option') !== false && $value != '') {
$status = $request->input('correct') == $key ? 1 : 0;
QuestionsOption::create([
'question_id' => $question->id,
'option' => $value,
'correct' => $status
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment