Created
November 12, 2017 13:35
-
-
Save Cyberiaaxis/aaeecf1a5909b6a5f2a1bf8edb2ada3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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