/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // if (!$request->input('answer')) { return $this->respondUnprocessed(); } QuestionAnswer::create(['answer' => $request->input('answer'), 'question_id' => $request->input('question_id'), 'checked' => $request->input('checked')]); return $this->respondCreated("Data successfully created"); }
/** * Display the specified resource. * * @param $answer array post data * @param $user_id user id * @param $session_id session of material * @param $material_id * @internal param int $id * @return Response */ protected function createMaterialAnswer(array $answer, $user_id, $session_id, $material_id) { $insertedAnswer = QuestionAnswer::create($answer); $this->dispatch(new QuestionHasBeenAnswered($insertedAnswer, $user_id, $session_id)); $answer_id = $insertedAnswer->id; if (!$answer_id) { return false; } return $this->updateMaterialData($material_id, $answer_id); }
public function run() { QuestionAnswer::truncate(); $faker = Faker\Factory::create(); $authorIds = User::lists('id'); $questionIds = Question::lists('id'); for ($i = 0; $i < 10; $i++) { QuestionAnswer::create(['answer' => $faker->sentence, 'status' => $faker->randomElement(array(0, 1)), 'question_id' => $faker->randomElement($questionIds), 'author_id' => $faker->randomElement($authorIds)]); } }