I need to give selected value like this html:
<select name="myselect" id="myselect">
<option value="1">Item 1</option>
<option value="2" selected='selected'>Item 2</option>
how can I achieve this, with laravel forms?
I need to give selected value like this html:
<select name="myselect" id="myselect">
<option value="1">Item 1</option>
<option value="2" selected='selected'>Item 2</option>
how can I achieve this, with laravel forms?
To echo some other answers here, the code I just used with 5.6 is this
In order to be able to use the Form Helper from LaravelCollective I took a look at https://laravelcollective.com/docs/master/html#drop-down-lists
I also had to composer require the dependency also so that I could use it in my projects
Lastly I altered my
config/app.php
and added the following in the$aliases
arrayhttps://laravelcollective.com/docs/master/html should be consulted if any of the above ceases to work.
Setting selected option is very simple in laravel form :
Output will be :
Just Simply paste this code you will get the desired output that you needed.
use this package and check the docs:
https://laravelcollective.com/docs/5.2/html#drop-down-lists
form you html , you need use this mark
You can also try this for limited options:
Everybody talking about you go using
{!! Form::select() !!}
but, if all you need is to use plain simple HTML.. here is another way to do it.the
old()
function is useful when you submit the form and the validation fails. So that,old()
returns the previously selected value.