@props([ 'options' => [], 'selectedOptions' => null, ]) @php // Evita que valores tipo array queden dentro de $attributes (causan: trim() expects string, array given) // y hace más robusto el soporte para wire:model, wire:model, wire:model.live, etc. $attributesArray = $attributes->getAttributes(); $wireModelKey = collect($attributesArray) ->keys() ->first(function ($key) { return is_string($key) && \Illuminate\Support\Str::startsWith($key, 'wire:model'); }); $wireModel = $wireModelKey ? ($attributesArray[$wireModelKey] ?? null) : null; $id = $attributesArray['id'] ?? ('select2_' . (string) \Illuminate\Support\Str::uuid()); $selectedWrapped = \Illuminate\Support\Arr::wrap($selectedOptions); @endphp