started on logic for taking tests
This commit is contained in:
parent
74cbeb2eb8
commit
3a8ec97891
7 changed files with 84 additions and 11 deletions
app/Http/Controllers
|
@ -8,15 +8,43 @@ use App\Test;
|
|||
|
||||
class TestController extends Controller
|
||||
{
|
||||
public function test(Test $test)
|
||||
public function startTest(Test $test)
|
||||
{
|
||||
$test_id = $test->id;
|
||||
$question_count = 1;
|
||||
$questions = $test->questions;
|
||||
$options = $questions[0]->options;
|
||||
return view('tests.index', compact('questions'), compact('options'));
|
||||
$rand_questions = $questions->random($test->question_count);
|
||||
$shuffled_questions = $rand_questions->shuffle();
|
||||
session(['questions' => $shuffled_questions, 'question_count' => $question_count, 'test_id' => $test_id]);
|
||||
return redirect()->action('TestController@showQuestion');
|
||||
}
|
||||
|
||||
public function answer()
|
||||
public function showQuestion()
|
||||
{
|
||||
echo "Hello";
|
||||
$question_count = session('question_count');
|
||||
$questions = session('questions');
|
||||
$question = $questions->get($question_count-1);
|
||||
$options = $question->options;
|
||||
$shuffled_options = $options->shuffle();
|
||||
session(['options' => $shuffled_options]);
|
||||
return view('tests.index', compact('question'), compact('shuffled_options'));
|
||||
}
|
||||
|
||||
public function answerQuestion ()
|
||||
{
|
||||
$question_count = session('question_count');
|
||||
$questions = session('questions');
|
||||
$question = $questions->get($question_count-1);
|
||||
$question_count++;
|
||||
session(['question_count' => $question_count]);
|
||||
if (request()->get('answer') != $question->answer_id) {
|
||||
return view('tests.false');
|
||||
}
|
||||
return view('tests.true');
|
||||
}
|
||||
|
||||
public function showAnswer()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue