added better feedback page on test after each question
This commit is contained in:
parent
d4d8801f8b
commit
c8ebd1756f
10 changed files with 336 additions and 15 deletions
app/Http/Controllers
|
@ -43,10 +43,10 @@ class TestController extends Controller
|
|||
{
|
||||
$question = session('questions')->get(session('question_counter')-1);
|
||||
$options = session('options');
|
||||
$answers = [];
|
||||
$answers = collect([]);
|
||||
foreach ($options as $option) {
|
||||
if (array_key_exists("answer{$option->id}", request()->all())) {
|
||||
$answers[] = $option;
|
||||
$answers->push($option);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ class TestController extends Controller
|
|||
if (session('test')->hasFailed(session('wrong_answers'))) {
|
||||
session(['has_failed' => true]);
|
||||
}
|
||||
session(['answers' => $answers]);
|
||||
session(['question_counter' => session('question_counter')+1]);
|
||||
return redirect()->action('TestController@showAnswer');
|
||||
}
|
||||
|
@ -103,7 +104,8 @@ class TestController extends Controller
|
|||
|
||||
$question = session('questions')->get(session('question_counter')-2);
|
||||
$options = session('options');
|
||||
return view('tests.answer', compact("question"), compact("options"));
|
||||
$answers = session('answers');
|
||||
return view('tests.answer', compact("question"), compact(["options", "answers"]));
|
||||
}
|
||||
|
||||
public function testRetry(Test $test)
|
||||
|
|
Reference in a new issue