Does anybody know how can I set in my select box the first option to empty value?
I\'m getting the data from my DB, and I would like to set the option by default as \"P
This worked for me on Laravel 5.4.
{{ Form::select('agency', $agency, null, [
'placeholder' => 'Please select ...',
'class' => 'form-control'
]) }}
There are 2 methods to do this:
{{ Form::select('user', array('default' => 'Please select one option') + $users, 'default') }}
Or
<select>
<option selected disabled>Please select one option</option>
@foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->name }}</option>
@endforeach
</select>
If you are using the HTML package by LaravelCollective, you do the following..
Form::select('size', array('L' => 'Large', 'S' => 'Small'), null, ['placeholder' => 'Pick a size...']);
I found that 'default'=>'Please select'
doesn't work with the HTML5 required attribute.
This does work:
$listOfValues = [1 => 'Choice 1'];
Form::select('fieldname',[null=>'Please Select'] + $listOfValues);
If you don't like modern PHP syntax,
$listOfValues = array(1 => 'Choice 1');
$listOfValues[null] = 'Please Select';
Form::select('fieldname', $listOfValues);
But the point is to have a label for the null value.
In the view
{!! Form::select('qualification_level', $qualification , old('Qualification_Level'), ['class' => 'form-control select2', 'placeholder' => '']) !!}
In the Controller $qualification = \App\Qualification::pluck('name','id')->prepend('Please Select');
in controller
$data['options']=Entity::pluck('name','id')->prepend('Please Select','');
return view('your_view_blade',$data);
in view blade
{!! Form::select('control_name',$options,null,['class'=>'your_class']) !!}