如何在Laravel中显示`select`元素的旧数据?

时间:2017-05-07 13:19:58

标签: html laravel-5

如何在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>

1 个答案:

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