Select & Multiselect

The options can be callable or associative/flat array
$options = ['Wifi' => 'wf', 'Bluetooth' => 'bl', 'Ethernet' => 'eth'];
$options = ['Wifi', 'Bluetooth', 'Ethernet'];Select
Does not use @entangle.
Select::make('Select')
->options($options)
->default('wf')
->fieldWidth('w-full sm:max-w-sm')
->wire('defer')// if you don't want a network request on every selection
->rules(['nullable', Rule::in(array_values($options))]);Multiselect
Uses @entangle. Is deferred by default.
MultiSelect::make('Multi Select')
->options($options)
->default(['wf'])
->deferEntangle(false)//remove if you want the field to be deferred
->fieldWidth('w-full sm:max-w-sm')
->wire('defer')// if you don't want a network request on every selection
->rules(['nullable', Rule::in(collect($options)->values()->implode(','))]); value is a string
Livewire example
value is an array
Livewire example
Methods
->options($options)
A list or flat
key => valuebasedArray,CollectionorClosure.OBSERVE: if you use a callable, it will be executed on EVERY re-render of the component! Maybe you should consider setting the
$optionsinmount()instead?Tip: use a component method that returns an array;
->options($this->someMethod())
->placeholder(string $placeholder)
Display a message when no item is selected.
Last updated
Was this helpful?