How to recover old values from select inputs?

Asked

Viewed 63 times

2

Follow the code of the Lade:

<select name="tipo_id" class="form-control col-md-3 col-xs-12">
    <option value=""></option>
    @foreach ($tipos as $tipo )
       <option name="tipo_id" value="{{$tipo->id}}">
           {{$tipo->description}}
       </option>
    @endforeach
</select>

1 answer

3


To retrieve the chosen value after a request call the function old('tipo_id') and seeing its code was made the <select></select> at hand use a if within the option to set what was chosen, example:

<select name="tipo_id" class="form-control col-md-3 col-xs-12">
    <option value=""></option>
    @foreach ($tipos as $tipo )
       <option name="tipo_id" value="{{$tipo->id}}" @if(old('tipo_id')==$tipo->id) {{'selected'}} @endif>
           {{$tipo->description}}
       </option>
    @endforeach
</select>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.