I am in trouble.
laravel under 5.0 code
testController.php
$prefs = ['' => 'Please Select'] + Prefectures::lists('name', 'id');
:
:
test.blade.php
{{ Form::select('pref', $prefs, null) }}
However, in laravel 5.0 or more, it is an error in this code. the blade file even if the following result was the same.
test.blade.php
{!! Form::select('pref', $prefs, null) !!}
I want to create an array that you added one item to the obtained values from the database.
controller
$prefs = ['' => 'Please Select'] + Prefectures::lists('name', 'id');
view
{!! Form::select('pref', $prefs, null) !!}
double curly bracket will escape. so coming from laravel 4.0 you should change {{ to {!!. I was also confused before when i migrated to 5.0.
this should work fine.
Update This what i usually do in my code.
$prefs = Prefectures::lists('name', 'id');
return view('view', compact('prefs'));
{!! Form::select('pref', ['' => 'Please Select'] + $prefs, null) !!}
Puedes usar el método prepend.
$departments = Department::lists('name', 'id')->prepend('Please Select');
Another solution.
{!! Form::select('posts',
[null => 'Title'] + json_decode($posts->pluck('title', 'id'), true), null)
!!}