You just follow this discussion. I hope you will get your answer-
https://stackoverflow.com/questions/35611945/old-value-in-multiple-select-option-in-laravel-blade
I"m trying to figure out what I"m doing wrong in my old() function so that if my form fails it will take the selections that were made if there were some and when it reloads the form it will prepopulate the options the user had selected. I also am including the validation rules.
'matches.*.stipulations' => 'array|not_in:0',
<select class="form-control" id="stipulations" name="matches[{{ $x }}][stipulations][]" multiple="multiple">
<option value="0">Choose One</option>
@foreach(App\Models\Stipulation::all() as $stipulation)
<option value="{{ $stipulation->id }}" {{ old('matches.'.$x.'.stipulations[]') == $stipulation->id ? 'selected="selected"' : '' }}>{{ $stipulation->name }}</option>
@endforeach
</select>
How about this?
<select class="form-control" id="stipulations" name="matches[{{ $x }}][stipulations][]" multiple="multiple">
<option value="0">Choose One</option>
@foreach(App\Models\Stipulation::all() as $stipulation)
<option value="{{ $stipulation->id }}" @if(old('matches['.$x.'][stipulations][]') == $stipulation->id) {{ 'selected' }} @endif>{{ $stipulation->name }}</option>
@endforeach
</select>
Please or to participate in this conversation.