我有下拉的问题,我总是得到第一个记录。有什么建议吗?
$category = $request->input('article_category');
<select class="form-control" name="article_category">
<option value="" disabled>--Please select article category</option>
@foreach ($categories as $category)
<option value="{{ $category->id }}">{{ $category->title }}</option>
@endforeach
答案 0 :(得分:1)
请进行以下更改......
<select class="form-control" name="article_category">
<option value="" disabled>--Please select article category</option>
@foreach ($categories as $category)
<option value="{{ $category->id }}" @if(request()->input('article_category') == $category->id){{ 'selected' }}@endif>{{ $category->title }}</option>
@endforeach
</select>
$category = $request->input('article_category')
被foreach写的foreach($categories as $category)
覆盖。