Reputation: 23
I am using multiselect dropdown but not able to get old values(by using old('') in laravel blade)on submit.Please tell where i am doing wrong.Below i am sharing code.
<div class="form-group">
<label for="integration">Integration</label>
<div class="select2-purple">
<select id="integration" class="form-control form-select form-select-lg col-lg-12 select2" multiple="multiple" aria-label=".form-select-lg example" data-dropdown-css-class="select2-purple" name="integration[]">
<option value=''>Select Integration</option>
@foreach($integartion as $integartions)
<option value="{{ $integartions->ecom_channel }}" @if(isset($company) && in_array($integartions->ecom_channel, $CmpIntegartion) ) selected @endif>{{ $integartions->ecom_channel }}</option>
@endforeach
</select>
@if ($errors->has('integration'))
<span class="text-danger">{{ $errors->first('integration') }}</span>
@endif
</div>
</div>
Upvotes: 0
Views: 815
Reputation: 609
<select name="integration[]">
<option value=''>Select Integration</option>
@foreach($integartion as $integartions)
<option value="{{ $integartions->ecom_channel }}" @if(old('integration') && is_array(old('integration')) && in_array($integartions->ecom_channel, old('integration')) selected @endif>{{ $integartions-> ecom_channel}}</option>
@endforeach
</select >
Your data will be stored like this in old: integration[0] = somevalue, integration[1] = somevalue
So you first check if your old('integration') is not null, then you check if its an array, then you check if the current item of loop exists inside that array!!
Upvotes: 1