我想在带有循环数据的选择字段内添加空选项。这是我正在使用的代码
<div class="form-group {{$errors->has('duration_id')}}">
{!! Form::label('duration_id', 'Duration Id', ['class' => 'control-label']) !!}
{!! Form::select('duration_id', $durations, null, ('required' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control']) !!}
{{$errors->first('duration_id')}}
</div>
如何添加“ --select duration--”之类的内容作为第一选择?
向表单选择元素添加占位符
Form::select('duration_id', $durations, null, ['placeholder' => '--select duration--'], ('required' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control'])
从docs开始
这将创建一个没有值的<option>
元素作为下拉菜单的第一个选项。
echo Form::select('size', ['L' => 'Large', 'S' => 'Small'], null, ['placeholder' => 'Pick a size...']);