@props(['name', 'label' => null, 'options' => [], 'value' => null, 'placeholder' => null, 'hint' => null, 'creatable' => false, 'source' => null, 'optionSets' => []]) {{-- with a search box, for long lists such as every country. The choice posts through a hidden input; arrow keys move, Enter picks, Escape closes. A placeholder prompts a required field; otherwise it's an empty first choice. --}} {{-- [creatable] also takes typed text that isn't listed. With a [source] (another searchable select's name), the options switch to [optionSets][its new value], e.g. a currency's symbols. --}} @php($key = str_replace(['[', ']'], ['.', ''], $name)) {{-- errors and old input use dot keys --}} @php($id = $attributes->get('id', $name)) @php($emptyChoice = $placeholder !== null && ! $attributes->get('required')) @php($toChoices = fn ($set) => collect($set)->map(fn ($optionLabel, $optionValue) => ['value' => (string) $optionValue, 'label' => __($optionLabel)])->values()) @php($current = (string) old($key, $value)) @php($choices = $toChoices(collect($emptyChoice ? ['' => $placeholder] : [])->union($options))) @php($choices = $creatable && $current !== '' && ! $choices->contains('value', $current) ? $choices->push(['value' => $current, 'label' => $current]) : $choices)
@if ($label) @endif
  • {{ __('No matches') }}
@if ($hint)

{{ $hint }}

@endif @error($key)

{{ $message }}

@enderror