{{-- Shared question editor fields. Vars: $q (ExamQuestion|null), $domains (collection) --}} @php $letters = range('A', 'H'); $qType = old('type', $q?->type ?? 'single'); if (is_array(old('options'))) { $picked = (array) old('correct', []); $rows = collect(old('options'))->values()->map(fn ($t, $i) => ['text' => $t, 'correct' => in_array($letters[$i] ?? '', $picked, true)])->all(); } elseif ($q?->exists) { $rows = collect($q->options)->map(fn ($o) => ['text' => $o['text'], 'correct' => in_array($o['key'], (array) $q->correct, true)])->all(); } else { $rows = array_fill(0, 4, ['text' => '', 'correct' => false]); } while (count($rows) < 2) { $rows[] = ['text' => '', 'correct' => false]; } $rows = array_slice($rows, 0, 8); @endphp