fixed bug where refreshing on question page during test taking would advance the question
This commit is contained in:
parent
634a43b93d
commit
bde382c1ff
5 changed files with 14 additions and 6 deletions
app/Http/Controllers
|
@ -52,5 +52,6 @@ class HomeController extends Controller
|
|||
{
|
||||
$user = Auth::user();
|
||||
$user->updateEmail(request()->all());
|
||||
return redirect('/settings');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,12 @@ class TestController extends Controller
|
|||
//insert session flash
|
||||
return redirect('/home');
|
||||
}
|
||||
session(['questions' => $test->randomizeQuestions(), 'question_counter' => 0, 'test' => $test, 'wrong_answers' => 0, 'is_correct' => false, 'has_failed' => false, 'last_question' => false]);
|
||||
session(['questions' => $test->randomizeQuestions(), 'question_counter' => 1, 'test' => $test, 'wrong_answers' => 0, 'is_correct' => false, 'has_failed' => false, 'last_question' => false]);
|
||||
return redirect()->action('TestController@showQuestion');
|
||||
}
|
||||
|
||||
public function showQuestion()
|
||||
{
|
||||
session(['question_counter' => session('question_counter')+1]);
|
||||
$question = session('questions')->get(session('question_counter')-1);
|
||||
$options = $question->options->shuffle();
|
||||
session(['options' => $options]);
|
||||
|
@ -75,12 +74,13 @@ class TestController extends Controller
|
|||
if (session('test')->lastQuestion(session('question_counter'))) {
|
||||
session(['last_question' => true]);
|
||||
}
|
||||
session(['question_counter' => session('question_counter')+1]);
|
||||
return redirect()->action('TestController@showAnswer');
|
||||
}
|
||||
|
||||
public function showAnswer()
|
||||
{
|
||||
$question = session('questions')->get(session('question_counter')-1);
|
||||
$question = session('questions')->get(session('question_counter')-2);
|
||||
$options = session('options');
|
||||
return view('tests.answer', compact("question"), compact("options"));
|
||||
}
|
||||
|
|
Reference in a new issue