@foreach($fieldDefinitions as $def)
@php
$inputName = 'field_'.$def->id;
$label = $def->label ?: $def->key;
$isRequired = (bool)$def->is_required;
$current = old($inputName, null);
@endphp
@php
// normalize type (avoid trailing spaces / different casing)
$type = trim(strtolower((string) $def->input_type));
$opts = method_exists($def, 'options') ? $def->options() : (json_decode($def->options_json, true) ?: []);
// for debugging: you can remove this later
$debug = "type={$type}; opts_count=" . count($opts);
@endphp