3 回答
TA贡献1773条经验 获得超3个赞
你可以这样做:
<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>
TA贡献1712条经验 获得超3个赞
您可以使用它来显示选择列表中的所选项目
<?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>
TA贡献1830条经验 获得超3个赞
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>
- 3 回答
- 0 关注
- 154 浏览
添加回答
举报