@php // Closure to convert string to array for radios/selects $convertStringToArray = function($string) { $result = []; if(!empty($string)){ foreach(explode(',', $string) as $part){ $values = explode('##', $part); if(count($values) === 2){ $result[] = [ 'value' => $values[0], 'label' => ucfirst($values[1]) ]; } } } return $result; }; // Group fields by group_id $formGroups = []; foreach($formList as $field){ $formGroups[$field->group_id][] = $field; } @endphp