@php $indexes = $indexes ?? []; @endphp @foreach($questions as $qIndex => $question) @php $currentIndexes = array_merge($indexes, [$qIndex]); $fieldConfig = is_string($question->field_config) ? json_decode($question->field_config, true) : $question->field_config; $namePath = function($field) use ($section, $currentIndexes) { $path = "sections[" . $section->title . "][questions]"; foreach ($currentIndexes as $i) { $path .= "[" . $i . "][children]"; } $path = preg_replace('/\[children\]$/', '', $path); return $path . "[" . $field . "]"; }; @endphp