Hi, my name is David Carr and I'm a PHP Developer.


Blog Archives Categories Authors About Me Open Source Books Contact Me

Sponsor Me

Help support the blog so that I can continue creating new content!

My Latest Book

Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Select

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>



 
Copyright © 2009 - 2022 David Carr. All code MIT license. All rights reserved.