我已经从数据库中获取了数据
<div class="input-field col s12 m4 l4">
<select multiple name="store_type[]" required="">
<option selected="" disabled="">{{$value->store_type}}</option>
<option value="Dine-in">Dine-in</option>
<option value="Take-out">Take-out</option>
<option value="Home Delivery">Home Delivery</option>
<option value="Drive Thru">Drive Thru</option>
</select>
<label>Store Type</label>
</div>
。我希望输出单独选择那些结果。
示例:
如果商店类型分配了“用餐” 唯一选择的是“用餐”
看看我分配的进餐,外卖,送货上门,直通车。
必须选中所有结果复选框。
谢谢..
答案 0 :(得分:1)
您可以通过将数据作为数组返回,然后编写以下内容来完成此操作:
@php
$data =explode(',',$value->store_type);
@endphp
<div class="input-field col s12 m4 l4">
<select multiple name="store_type[]" required="">
<option selected="" disabled="">{{$value->store_type}}</option>
<option value="Dine-in" {{in_array('Dine-in',$data)?'selected':''}}>Dine-in</option>
<option value="Take-out" {{in_array('Take-out',$data)?'selected':''}}>Take-out</option>
<option value="Home Delivery" {{in_array('Home Delivery',$data)?'selected':''}}>Home Delivery</option>
<option value="Drive Thru" {{in_array('Drive Thru',$data)?'selected':''}}>Drive Thru</option>
</select>
<label>Store Type</label>
</div>