控制器:
$employee = Staff::where('staff_id', '=', $id)->where('user_role', '=','Employee')->first();
$emp_loc = $employee->locations()->pivot()->only('loc_id');
$locations_list = Location::lists('address1', 'loc_id'); //get list of locations
看法:
<!--location -->
<div class="control-group">
<label class="control-label">Location</label>
<div class="controls">
@if(isset($emp_loc))
{{ Form::select('location', $locations_list, $emp_loc) }}
@else
{{ Form::select('location', $locations_list) }}
@endif
</div>
</div>
第三个参数是选择框的默认值,但它总是从第一个值开始。
源代码:
<div class="control-group">
<label class="control-label">Location</label>
<div class="controls">
<select name="location"><option value="1">Bethel</option><option value="2">Brooklyn</option><option value="3">Germantown</option><option value="4">Memphis</option><option value="5">Brooklyn</option></select> </div>
</div>
没有设置默认值?