Hi, my name is David Carr and I'm a PHP Developer.
Help support the blog so that I can continue creating new content!
Learn how to build modular applications with Laravel Find out more
create a select menu set the name and placeholder for the initial option
<x-form.select name='types' placeholder='Select'>
</x-form.select>
Leave off the placeholder to have only the select and options that can be selected
<x-form.select name='types'>
</x-form.select>
In order to set the option, an array is needed and is looped over and then a nested component is used.
Pass in the key and value from the array
@php
$options = [1 => 'one', 2 => 'two', 3 => 'three'];
@endphp
<x-form.select name='types' placeholder='Select'>
@foreach($options as $key => $value)
<x-form.selectoption key='{{ $key }}' value='{{ $value }}'></x-form.selectoption>
@endforeach
</x-form.select>