@extends('layouts.portal') @php $letters = fn ($opts) => collect($opts)->map(function ($o, $i) { if (is_array($o)) { return ['key' => (string) ($o['key'] ?? chr(65 + $i)), 'text' => (string) ($o['text'] ?? $o['label'] ?? '')]; } return ['key' => is_int($i) ? chr(65 + $i) : (string) $i, 'text' => (string) $o]; })->values(); $review = session('quiz_review') ?: ($last?->answers ?? null); $fresh = session()->has('quiz_review'); $passed = $last && $last->status === 'passed'; $qCount = $questions->count(); $courseModel = $quiz->course; @endphp @section('title', $quiz->title) @section('subtitle', ($courseModel ? $courseModel->title.' · ' : '').$qCount.' questions · pass mark '.$quiz->pass_percent.'%') @section('actions') @if($courseModel) Course home@endif @endsection @section('content')
@if($last)

{{ $passed ? 'You passed this quiz' : 'Not passed yet' }}

{{ $fresh ? 'Just now' : 'Last attempt '.$last->submitted_at?->diffForHumans() }} · pass mark {{ $quiz->pass_percent }}%. @if($review){{ collect($review)->where('ok', true)->count() }} of {{ count($review) }} correct.@endif

@if($review)

Answers & explanations

From your {{ $fresh ? 'latest' : 'last' }} attempt
@foreach($quiz->questions as $i => $q) @php $r = $review[$q->id] ?? ['given' => null, 'ok' => false]; $opts = $letters($q->options)->keyBy('key'); $state = $r['given'] === null || $r['given'] === '' ? 'skip' : ($r['ok'] ? 'ok' : 'no'); @endphp
Question {{ $i + 1 }}{{ ['ok' => 'Correct', 'no' => 'Incorrect', 'skip' => 'Not answered'][$state] }}
{{ \App\Support\ExamText::html($q->question) }}
Your answer
@if($state === 'skip')No answer given@else{{ $opts[$r['given']]['text'] ?? $r['given'] }}@endif
@if($state !== 'ok')
Correct answer
{{ $opts[$q->correct_key]['text'] ?? $q->correct_key }}
@endif
@if($q->explanation)

Why: {{ $q->explanation }}

@endif
@endforeach
@endif @endif
@csrf

{{ $last ? 'Try again' : 'Answer the questions' }}

0 of {{ $qCount }} answered
@forelse($questions as $i => $q)
{{ $i + 1 }} {{ \App\Support\ExamText::html($q->question) }} @foreach($letters($q->options) as $o) @endforeach
@empty @endforelse
@if($qCount)
You can retake this quiz as often as you like. Your best result is kept.
@endif
@endsection @push('scripts') @endpush