@extends('layouts.app') @section('title', 'Survey Attempt Details') @section('content')
Survey Attempt Details - #{{ $attempt->id }}
Attempt Information
@php /** * Local helper to normalize answer strings in the view to avoid showing accumulated backslashes */ $normalizeViewAnswer = function ($answer) { if (is_null($answer)) return 'No Answer'; if (!is_string($answer)) return is_scalar($answer) ? (string)$answer : json_encode($answer, JSON_UNESCAPED_UNICODE); $clean = str_replace('\\/', '/', $answer); $prev = null; while ($clean !== $prev) { $prev = $clean; $clean = stripslashes($clean); } $clean = trim($clean); return $clean === '' ? 'No Answer' : $clean; }; @endphp
Attempt ID
{{ $attempt->id }}
Survey Name
{{ $attempt->survey->survey_name ?? '' }}
Survey Type
{{ $attempt->survey->survey_type ?? '' }}
User Name
{{ $attempt->user?->first_name ?? '' }}{{ $attempt->user?->last_name ?? '' }}
User Email
{{ $attempt->user->email ?? '' }}
Attempt Status
{{ ucfirst($attempt->save_type) }}
Started At
{{ $attempt->attempt_started_at ? $attempt->attempt_started_at->format('Y-m-d H:i') : '' }}
Last Saved At
{{ $attempt->last_saved_at ? $attempt->last_saved_at->format('Y-m-d H:i') : '' }}
Channel
{{ $attempt->survey->channel->name ?? '' }}
Detailed Answers
@if ($answers->isEmpty())

No answers found for this attempt.

@else @php $groupedAnswers = $answers->groupBy( fn($answer) => $answer->questionGroup->question_group_name ?? 'Ungrouped', ); @endphp @foreach ($groupedAnswers as $groupName => $groupAnswers)
{{ $groupName }}
@foreach ($groupAnswers as $answer) @endforeach
Question Question Type Answer
{{ $answer->question->question ?? '' }} {{ ucfirst(str_replace('_', ' ', $answer->question->question_type ?? '')) }} @php $type = $answer->question->question_type ?? ''; $rawAns = is_string($answer->answer) && str_starts_with($answer->answer, '"') && str_ends_with($answer->answer, '"') ? substr($answer->answer, 1, -1) : $answer->answer; // Normalize for display $ans = $normalizeViewAnswer($rawAns); $decodedAnswer = json_decode($ans, true); @endphp @switch($type) @case('single_line_text_box') @case('multiple_line_text_box') @case('numerical') {{ $ans ?? '' }} @break @case('radio') @case('dropdown') {{-- Show single selected option --}} {{ $ans ?? '' }} @break @case('checkbox') @case('multiple_choice') {{-- Show multiple selected options as list --}} @if (is_array($decodedAnswer))
    @foreach ($decodedAnswer as $ansItem)
  • {{ $normalizeViewAnswer($ansItem) }}
  • @endforeach
@else {{ $ans ?? '' }} @endif @break @case('matrix') @php $decodedAnswer = json_decode($ans, true); @endphp @if (is_array($decodedAnswer)) @foreach ($decodedAnswer as $row => $cols) @if (is_array($cols)) @foreach ($cols as $col) @endforeach @else @endif @endforeach
{{ $row }}{{ $normalizeViewAnswer($col) }}{{ $normalizeViewAnswer($cols) }}
@else {{ $ans ?? '' }} @endif @break @case('datetime') @php $finalDate = null; if (!empty($ans)) { // Remove any surrounding quotes $cleanedStr = trim($ans, '"'); // Remove the specific trailing part $finalDate = str_replace(':00.000', '', $cleanedStr); } @endphp {{ $finalDate ?? '' }} @break @case('time') @php try { $formattedTime = !empty($ans) ? \Carbon\Carbon::parse($ans)->format('H:i') : null; } catch (\Exception $e) { $formattedTime = null; } @endphp {{ $formattedTime ?? '' }} @break @default {{ $ans ?? '' }} @endswitch
@endforeach @endif
@endsection @push('js') @endpush