如何在Laravel中显示select
元素的旧数据?
数据可以input
显示,如下所示:
<input id="name" name="name" class="form-control" type="text" value="{{ old('name', $user->name) }}">
当元素为select
时,如何显示旧数据?
<select class="form-control" name="gender">
<option value="male">male</option>
<option value="female">female</option>
</select>
答案 0 :(得分:0)
尝试一下:
<label for="name">Tags</label>
<select name="tags[]" class="form-control select-tag" multiple>
@foreach($tags as $tag)
<option value="{{$tag->id}}" {{in_array($tag->id, old("tags") ?: []) ? "selected": ""}}>{{$tag->name}}</option>
@endforeach
</select>