@foreach($fieldDefinitions as $def)
@php
$inputName = 'field_'.$def->id;
$label = $def->label ?? $def->key;
$isRequired = (bool)$def->is_required;
$existing = isset($values[$def->id]) ? $values[$def->id]->value : null;
$existingArr = null;
if ($existing && (strtolower($def->input_type) === 'multiselect' || strtolower($def->input_type) === 'checkbox')) {
$existingArr = json_decode($existing, true) ?: [];
}
$type = strtolower($def->input_type);
@endphp
@switch($type)
@case('select')
@break
@case('multiselect')
@break
@case('textarea')
@break
@case('date')
@break
@case('number')
@break
@case('file')
@if(isset($files[$def->id]))
@foreach($files[$def->id] as $f)
@endforeach
@endif
@break
@case('checkbox')
@foreach($def->options as $idx => $opt)
@php
$val = is_array($opt) ? ($opt['value'] ?? ($opt['label'] ?? json_encode($opt))) : $opt;
$labelOpt = is_array($opt) ? ($opt['label'] ?? $val) : $opt;
$checked = in_array($val, old($inputName, $existingArr ?: [])) ? 'checked' : '';
@endphp
@endforeach
@break
@default
@endswitch
@error($inputName)
{{ $message }}
@enderror