Highlight all selected ids in the multiselect drop-down list in laravel 5.4 with crop selected

I have a drop-down name called designation, where the user can add some information against the multiple designation. If I add 1 entry against 3 notations, then I also need to select them during verification and editing time.

Ex: selected id {5,7,8} from [1 to 10].

<select id="forWhom" name="forWhom[]" multiple class="form-control chosen"> <option value="">--- Select ---</option> @foreach ($desgInfo as $key => $value) <option value="{{ $key }}" {{ old('forWhom',$info->forWhom) == $key ? 'selected' : ''}} />{{ $value }}</option> @endforeach </select> 

After adding this information, I save the selected identifier in a comma delimiter (,) ie 5,7,8.

How can I do this in laravel 5.4

0
source share
1 answer

After a little game, I got the result.

Here is a snippet of code.

While adding

 <select id="forWhom" name="forWhom[]" multiple class="form-control chosen"> <option value="">--- Select ---</option> @foreach ($desgInfo as $key => $value) <option value="{{ $key }}" {{ (collect(old('forWhom'))->contains($key)) ? 'selected':'' }} /> {{ $value }} </option> @endforeach </select> 

During editing , suppose you get the result of the selected identifiers in

$ info-> forWhom

 <select id="forWhom" name="forWhom[]" multiple class="form-control chosen"> <option value="">--- Select ---</option> @foreach ($desgInfo as $key => $value) <option value="{{ $key }}" {{ (collect(old('forWhom'))->contains($key)) ? 'selected':'' }} {{ (in_array($key,$info->forWhom)) ? 'selected' : ''}} /> {{ $value }} </option> @endforeach </select> 

Hope this helps someone else.

0
source

All Articles