@props([ 'name', 'label' => null, 'options' => [], // ['value' => 'label', ...] OR collection of objects with id/name 'optionValue' => 'id', 'optionLabel' => 'name', 'value' => null, 'placeholder' => null, 'required' => false, 'multiple' => false, 'help' => null, ]) @php $id = $attributes->get('id', $name); $selected = old($name, $value); if ($multiple && ! is_array($selected)) { $selected = $selected !== null ? (array) $selected : []; } // Detect whether the option list is associative ['value' => 'label'] // or a list of objects/models (User, etc). The previous version used // `reset($options)` which silently returns false on a Collection // (PHP 8 doesn't accept non-array there) — that flipped the detection // and caused the WHOLE model to be rendered as the option text via // its __toString JSON serializer. Symptom: option text showed // {"id":4,"name":"احمد...","specialization":"..."} // instead of the doctor's plain name. $first = match (true) { $options instanceof \Illuminate\Support\Collection => $options->first(), is_array($options) => (reset($options) ?: null), default => null, }; $isObjectList = is_object($first); @endphp