Added session flashes and validation errors to views and add session flashes in controllers

This commit is contained in:
mwalbeck 2016-11-01 13:03:39 +01:00
commit 4fc0d5c793
26 changed files with 72 additions and 86 deletions
app/Http/Controllers

View file

@ -20,14 +20,14 @@ class TestController extends Controller
$this->middleware('auth');
}
public function startTest(Test $test)
public function startTest(Test $test, Request $request)
{
if (null !== session("start_time") && session("time_limit") !== 0 && session("start_time")+session("time_limit") > time()) {
if (null !== session("start_time") && session("time_limit") !== 0 && session("start_time")+session("time_limit") > time() && $test->id === session('test')->id) {
return redirect()->action('TestController@showQuestion');
}
if (Auth::user()->testTaken($test->id)) {
//insert session flash
$request->session()->flash('status_failed', 'You have already taken this test!');
return redirect('/home');
}
session(['questions' => $test->randomizeQuestions(), 'question_counter' => 1, 'test' => $test, 'correct_answers' => 0, 'wrong_answers' => 0, 'is_correct' => false, 'has_failed' => false, 'last_question' => false, 'start_time' => time(), 'time_limit' => $test->time_limit]);