Add default value to select list in Laravel form::select
In Laravel 5.1 you can prepend the default item if the list is a collection (result of a Eloquent::lists()
)
$categories = Category::lists('name', 'id');
$categories->prepend('None');
You can use array_merge
like this:
{{
Form::select(
'myselect',
array_merge(['' => 'Please Select'], $categories),
$myselectedcategories,
array(
'class' => 'form-control',
'id' => 'myselect'
))
}}
Alternatively you can set the placeholder somewhere before the select:
$categories[''] = 'Please Select';
Update
To add the disabled attribute you can try this: (untested)
{{
Form::select(
'myselect',
array_merge(['' => ['label' => 'Please Select', 'disabled' => true], $categories),
$myselectedcategories,
array(
'class' => 'form-control',
'id' => 'myselect'
))
}}
Add 'placeholder' => 'Please Select'
into the Form::select
.
{!!
Form::select(
'myselect',
$categories,
null,
['class' => 'form-control', 'placeholder' => 'Please Select'])
!!}