选择选项,从数据库中选择值结果

时间:2018-06-24 11:17:54

标签: php laravel

我已经从数据库中获取了数据

<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>

。我希望输出单独选择那些结果。

示例:

如果商店类型分配了“用餐”  唯一选择的是“用餐”

Output that I like

看看我分配的进餐,外卖,送货上门,直通车。

必须选中所有结果复选框。

谢谢..

1 个答案:

答案 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>