{{-- resources/views/user/q6.blade.php --}} @extends('layouts.dashboard') @section('content')
@csrf @php $groupedQuestions = []; foreach($q6 as $q){ /* MAIN QUESTION example => 1 */ if(strpos($q->question_id, '.') === false){ $groupedQuestions[$q->question_id] = [ 'main_id' => $q->question_id, 'main_question' => $q->question_text, 'items' => [] ]; } } /* SUB QUESTIONS example => 1.1 */ foreach($q6 as $q){ if(strpos($q->question_id, '.') !== false){ $parts = explode('.', $q->question_id); $mainId = $parts[0]; if(isset($groupedQuestions[$mainId])){ $groupedQuestions[$mainId]['items'][] = [ 'id' => str_replace('.', '_', $q->question_id), 'text' => $q->question_text ]; } } } @endphp @foreach($groupedQuestions as $question)
{{ $question['main_id'] }}
{{ $question['main_question'] }}
@foreach($question['items'] as $item) @for($i=1; $i<=7; $i++) @endfor @endforeach
Questions Strongly Disagree Disagree Somewhat Disagree Neutral Somewhat Agree Agree Strongly Agree
{{ $item['text'] }}
@endforeach
@endsection