这是代码,当我提交表单时为什么我不能选择旧数据?
<select class="form-control" name="dateRestrict">
<option value="" {{ old('dateRestrict') == "" ? 'selected' : '' }}>Random Time</option>
<option value="d1" {{ old('dateRestrict') == "d1" ? 'selected' : '' }}>Yesterday</option>
<option value="w" {{ old('dateRestrict') == "w" ? 'selected' : '' }}>Last Week</option>
<option value="m" {{ old('dateRestrict') == "m" ? 'selected' : '' }}>Last Month</option>
<option value="y"{{ old('dateRestrict') == "y" ? 'selected' : '' }}>Last Year</option>
</select>
答案 0 :(得分:2)
在您的控制器中
if(isset($request->dateRestrict)){
$dateRestrict=$request->dateRestrict;
}
return view('view-name',compact('dateRestrict');
<强> Blade.php 强>
<select class="form-control" name="dateRestrict">
<option value="" @if(isset($dateRestrict) && $dateRestrict==""){{"selected"}} @endif >Random Time</option>
<option value="d1" @if(isset($dateRestrict) && $dateRestrict=="d1"){{"selected"}} @endif >Yesterday</option>
</select>