laravel select display selected value from database

Solutions on MaxInterview for laravel select display selected value from database by the best coders in the world

showing results for - "laravel select display selected value from database"
Gabriele
27 Jan 2019
1// prepare
2$artist = Artist::find($id);
3$tags = Tag::lists('title', 'id');
4$selected = $artist->tags->lists('id');
5
6// view, using FormBuilder
7{!! Form::select('tags[]', $tags, $selected, [ 'multiple' => 'multiple' ]) !!}
8
9// without FormBuilder
10<select name="tags[]" multiple>
11@foreach ($tags as $tag)
12    <option value="{{$tag->id}}" {{ (in_array($tag->id, $selected)) ? ' selected="selected"' : '' }}>{{$tag->title}}</option>
13@endforeach
14</select>
15