我有一个员工表格编辑。 我的问题是,我的编辑功能可以正常工作,但是我无法获取员工类型的值。
我有4个员工类型:
每次我去编辑表单时,下拉菜单中的员工类型始终在员工身上(我要显示,如果员工是“经理”,则下拉框显示“经理”)。
这是 editroledetails.blade.php
的代码<div class="form-group">
<label for="editCustomerType">Customer Type</label><br/>
<select name="editCustomerType">
<option value="Staff">Staff</option>
<option value="Supervisor">Supervisor</option>
<option value="Manager">Manager</option>
<option value="Super User">Super User</option>
</select>
</div>
控制器功能
public function editroledetails(Request $request)
{
$user = \Auth::user();
$userphone = 0;
$reportTo = DB::select(DB::raw("select username from customer_type where customer_type = 'Supervisor' or customer_type ='Manager' "));
$select = DB::select(DB::raw("select customer_type from customer_type "));
$data = [
'editUsername' => $request->editUsername,
'editNik' => $request->editNik,
'editEmail' => $request->editEmail,
'editRegIdentities' => $request->editRegIdentities,
'editReportTo' => $request->editReportTo,
'editID' => $request->editID
];
return view('editroledetails', compact('user', 'userphone', 'data', 'reportTo', 'select'));
}
答案 0 :(得分:0)
您可以执行以下操作:
<div class="form-group">
<label for="editCustomerType">Customer Type</label><br/>
<select name="editCustomerType">
@if($user->customer_type == 'Staff')
<option value="Staff">Staff</option>
@endif
@if($user->customer_type == 'Supervisor')
<option value="Supervisor">Supervisor</option>
@endif
@if($user->customer_type == 'Manager')
<option value="Manager">Manager</option>
@endif
@if($user->customer_type == 'Super User')
<option value="Super User">Super User</option>
@endif
</select>
</div>
答案 1 :(得分:0)
在选择选项上使用selected
属性
<div class="form-group">
<label for="editCustomerType">Customer Type</label><br/>
<select name="editCustomerType">
<option value="Staff" @if($user->customer_type == 'Staff')selected@endIf>Staff</option>
<option value="Supervisor" @if($user->customer_type == 'Supervisor')selected@endIf>Supervisor</option>
<option value="Manager" @if($user->customer_type == 'Manager')selected@endIf>Manager</option>
<option value="Super User" @if($user->customer_type == 'Super User')selected@endIf>Super User</option>
</select>
</div>
答案 2 :(得分:0)
您可以使用它在选择列表中显示所选项目
<?php
$customerTypes = [
'Staff' => 'Staff',
'Supervisor' => 'Supervisor',
'Manager' => 'Manager',
'Super User' => 'Super User',
];
?>
<div class="form-group">
<label for="editCustomerType">Customer Type</label><br/>
<select name="editCustomerType">
@foreach($customerTypes as $type)
<?php
$selected = "";
@if($user->customer_type == $type) {
$selected = "selected";
}
?>
<option value="{{ $type }}" {{ $selected }} >{{ $type }}</option>
@endforeach
</select>
</div>