提交刀片laravel后如何获取旧值选择选项

时间:2018-06-12 07:42:26

标签: html laravel laravel-blade

这是代码,当我提交表单时为什么我不能选择旧数据?

<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>

1 个答案:

答案 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>