在控制器验证后如何检查旧数据是否可用?我用过这个但它显示错误@if(\Illuminate\Http\Request::old('status')!=null) <option style="display: none" value="{{old('status')}}" hidden>{{old('status')}}</option>@endif也用过这个@if(isset(old('status'))) <option style="display: none" value="{{old('status')}}" hidden>{{old('status')}}</option>@endif完整形式是<form action="{{route('add-expense-store')}}" method="post" class="new-added-form"> {{ @csrf_field() }} <div class="row"> <div class="col-xl-8 col-lg-8 col-12 form-group"> <label>Expense Type</label> <select class="select2" name="type"> <option value="">Please Select</option> {{--<option value="Teacher's Salary">Teacher's Salary</option> <option value="Staff's Salary">Staff's Salary</option>--}} <option value="Transport">Transport</option> <option value="Mobile Bill">Mobile Bill</option> <option value="Utility Bill">Utility Bill</option> <option value="Stationary">Stationary</option> <option value="Print & Press">Print & Press</option> <option value="Photocopy & Compose">Photocopy & Compose</option> <option value="Entertainment & Hospitality">Entertainment & Hospitality</option> <option value="Donation">Donation</option> <option value="Program">Program</option> <option value="Personal or Owner">Personal or Owner</option> </select> </div>两者都出错。我如何检查我们在刀片中是否可用的旧值?现在我包括我的表单数据。如果找不到旧值,我想在这里隐藏。请帮忙解决这个问题。检查刀片中的旧数据。
1 回答
杨__羊羊
TA贡献1943条经验 获得超7个赞
您可以通过这种方式进行检查。记得从控制器以这种方式返回它
$validator = $this->validate($request, [
'type' => 'required',
'status' => 'required'
]);
if ( $validator->fails() ) {
return back()->withErrors( $validator )->withInput();
}
在你看来这样做
<select class="select2" name="status">
<option value="">Please Select</option>
<option value="Paid" {{ old('status') == 'Paid' ? 'selected' : '' }}>Paid</option>
<option value="Due" {{ old('status') == 'Due' ? 'selected' : '' }}>Due</option>
</select>
- 1 回答
- 0 关注
- 91 浏览
添加回答
举报
0/150
提交
取消