本文介绍了在laravel 5.4的多选下拉列表中选择所有选定的ID,并选择收获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个称为名称的下拉菜单,用户可以在其中添加一些针对多个名称的信息.如果我在3个指定中添加1个记录,那么我还需要在验证和编辑期间选择这些记录.
I have a dropdown called designation, where a user can add some information against multiple designation. If I add 1 record against 3 designation, then I need to select those during validation and edit time also.
Ex:从[1到10]中选择的ID的{5,7,8}.
Ex: Choosed id's {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>
添加了这些信息之后,我将这些选定的ID存储在逗号分隔符(即5,7,8)中.
After add of those information I store those selected id's in comma(,) separator i.e 5,7,8.
如何在laravel 5.4中进行选择
How can I make select this in laravel 5.4
推荐答案
玩了一段时间之后,我得到了结果.
After playing around a bit, I got the result.
这是代码段.
添加期间
<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>
在编辑过程中假设您在
<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>
我希望这会对其他人有所帮助.
I hope this will help some one else.
这篇关于在laravel 5.4的多选下拉列表中选择所有选定的ID,并选择收获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!