Reputation: 637
I want to add empty option inside the select field with loop data. Here's the code I'm using
<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>
How can I add something like "--select duration--" as the first selection?
Upvotes: 2
Views: 617
Reputation: 11044
Add a placeholder to your form select element
Form::select('duration_id', $durations, null, ['placeholder' => '--select duration--'], ('required' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control'])
From the docs
This will create an <option>
element with no value as the very first option of your drop-down.
echo Form::select('size', ['L' => 'Large', 'S' => 'Small'], null, ['placeholder' => 'Pick a size...']);
Upvotes: 2