在Laravel 5中使用“select”值重定向

I have searched a lot but didn't find any solution. I have some select box in my HTML form for which I need to keep the old values after redirecting back post input validations.

Here is my redirect code in controller

redirect()->back()->withInput()->withErrors($validator->messages());

I have tried using value={{old('somefieldname')}} But it only works for inputs and textareas.

PS : I also need to set old values in multiple="multiple" select.

Any help will be really appreciated.

If you are iterating in a loop then directly old will not work for select option

For example if you have something like that in your blade file then you can try this for selecting the current option after redirect

<select id="someId" name="someName">

 @foreach($someData as $data)
  <option value="{{ $data->id }}" @if(old('someName') == $data->id) selected @endif> {{ $data->name }} </option>
 @endforeach

</select>

Then it will select your current option.

If this is your problem then it might help.

In select you have to place selected=selected when option=value is equal to old. Also please consider using laravelcollective/html package. You can use it in this way:

{!! Form::select('type', ['' => 'Types'] + $options) !!}

And package automatically will take care about old values after redirecting back with after validation fails.