当我提交获取类明智主题列表时,我会获得类明智列表,但在提交表单后选择了类重置。请帮我解决此问题。here is my screen
这是我选择的代码..
<select name="class_id" class="form-control" id="class_id">
<option value="">{{trans('student_lang.student_select_class') }}</option>
@foreach($class as $classes)
<option value="{{$classes->id}}">{{$classes->title}}</option>
@endforeach
</select>
</div>
答案 0 :(得分:1)
<option value="{{ $classes->id }}" {{ request()->get("class_id") == $classes->id ? "selected" : "" }}>{{ $classes->title }}</option>
<option value="{{ $classes->id }}" {{ old("class_id") == $classes->id ? "selected" : "" }}>{{ $classes->title }}</option>
答案 1 :(得分:0)
aiohttp
或者
@foreach($class as $classes)
<option value="{{ $classes->id }}" @if($classes->id==old('class_id')) selected @endif>{{ $classes->title }}</option>
@endforeach
答案 2 :(得分:0)
只匹配所选的ID。
<select name="class_id" class="form-control" id="class_id">
<option value="">{{trans('student_lang.student_select_class') }}</option>
@foreach($class as $classes)
<option value="{{$classes->id}}" {{($classes->id == $user->id) ? 'selected' : ''}}>{{$classes->title}}</option>
@endforeach
</select>
尝试使用old()
<option value="{{$classes->id}}" {{($classes->id == old('class_id')) ? 'selected' : ''}}>{{$classes->title}}</option>
答案 3 :(得分:0)
试试这段代码 第一种形式Facade在使用后添加
{!! Form::select('class_id',$class,null,['class'=>'form-control']) !!}