/** * Run the database seeds. * * @return void */ public function run() { User::create(['id' => 1, 'email' => '*****@*****.**', 'password' => \Hash::make('123456'), 'name' => 'Airton Filho', 'status_level' => 1]); User::create(['id' => 2, 'email' => '*****@*****.**', 'password' => \Hash::make('123456'), 'name' => 'Rafael Froes', 'status_level' => 1]); Score::create(['user_id' => 1, 'value' => 29384]); Score::create(['user_id' => 2, 'value' => 29384]); }
public function run() { DB::table('scores')->delete(); Score::create(['score' => 1, 'quiz_id' => 2, 'student_id' => 1]); Score::create(['score' => 1, 'quiz_id' => 3, 'student_id' => 1]); Score::create(['score' => 2, 'quiz_id' => 2, 'student_id' => 2]); Score::create(['score' => 0, 'quiz_id' => 4, 'student_id' => 2]); Score::create(['score' => 1, 'quiz_id' => 3, 'student_id' => 3]); Score::create(['score' => 1, 'quiz_id' => 4, 'student_id' => 3]); }
public function store(Quiz $quiz, Request $request) { $student_id = Auth::user()->student()->first()->id; if (Score::whereQuizIdAndStudentId($quiz->id, $student_id)) { return "e"; } $points = 0; foreach ($request->all() as $r) { $ca = CorrectAnswer::whereQuestionId($r['question_id'])->first()->option_id; if ($ca == $r['option_id']) { $points++; } if (!Answer::whereStudentIdAndQuestionId($student_id, $r['question_id'])->first()) { Answer::create(['student_id' => $student_id, 'question_id' => $r['question_id'], 'option_id' => $r['option_id']]); } } $score = Score::create(['score' => $points, 'time' => time() - strtotime($quiz->date_time), 'quiz_id' => $quiz->id, 'student_id' => $student_id]); DB::table('quiz_student')->insert(['student_id' => $student_id, 'quiz_id' => $quiz->id]); return $score; }