@props([ 'name', 'options' => [], 'selected' => null, 'multiple' => false, 'placeholder' => null, 'required' => false, 'disabled' => false, ]) @php // Handle multiple select if ($multiple) { $selectedValues = is_array(old($name)) ? old($name) : (is_array($selected) ? $selected : []); // Convert all to strings for comparison $selectedValues = array_map('strval', $selectedValues); } else { // For single select, prioritize old input if (old($name) !== null) { $selectedValue = old($name); } elseif ($selected !== null) { $selectedValue = $selected; } else { $selectedValue = null; } } // Check if options is a 2D array (has optgroups) $hasOptgroups = false; if (!empty($options)) { $firstKey = array_key_first($options); $firstValue = $options[$firstKey]; $hasOptgroups = is_array($firstValue) && !is_numeric($firstKey); } @endphp