如何将此php选项更改为laravel表单?
<div class="form-group">
<label for="title">Food</label>
<select id="food" name="food_id" class="form-control" style="width:350px">
<option value="">--- Choose Food ---</option>
@foreach ($foods as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</div>
是这样的吗?
<div class="form-group">
<label for="title">Food</label>
{!! Form::select('food_id', $foods, $key => $value, ['class'=>'form-control', 'placeholder' => '--- Choose Food ---']) !!}
</div>
但它不起作用
修改的
实际上我通过了ajax
$('select[id="food"]').on('change', function() {
var foodID = $(this).val();
if(foodID) {
...
...
答案 0 :(得分:0)
Form::select('food_id', $foods, null, ['class'=>'form-control', 'placeholder' => '--- Choose Food ---','id'=>'food']);
第三个参数是当前选择的选项键。默认值为null。