我想知道下拉菜单或选择框如何工作....这里是我的选择框的代码
<select class="browser-default" id="com" name="company" >
<option value="{{$employee->company->id}}" disabled selected>{{$employee-
>company->name}}</option>
@foreach($compnies as $company)
<option value="{{$company->id}}" >{{$company->name}}</option>
@endforeach
</select><br>
这里我想更新我的数据但是有些时候用户无法更改选择框数据并保留前一个在这种情况下如何在默认情况下保存我的选中数据..... 这是我的控制器更新功能..
$employee->name = $request->input('name');
$employee->father_name = $request->input('father_name');
$employee->mobile = $request->input('mobile');
$employee->address = $request->input('address');
$employee->site_id= $request->site;
$employee->company_id = $request->company;
$employee->save();
所以基本上我想要如果用户不想更改选择选项....并更改其他数据,如移动...那么我如何保持我的旧选项已选择或默认选择的选择框。 ....
答案 0 :(得分:1)
你可以试试这个
<select class="browser-default" id="com" name="company" >
@foreach($compnies as $company)
<option value="{{$company->id}}" {{ $company->id == $employee->company_id ? 'selected' : ''}} >{{$company->name}}</option>
@endforeach
</select>