Answers for "laravel select display selected value from database"

PHP
0

laravel select display selected value from database

// prepare
$artist = Artist::find($id);
$tags = Tag::lists('title', 'id');
$selected = $artist->tags->lists('id');

// view, using FormBuilder
{!! Form::select('tags[]', $tags, $selected, [ 'multiple' => 'multiple' ]) !!}

// without FormBuilder
<select name="tags[]" multiple>
@foreach ($tags as $tag)
    <option value="{{$tag->id}}" {{ (in_array($tag->id, $selected)) ? ' selected="selected"' : '' }}>{{$tag->title}}</option>
@endforeach
</select>
Posted by: Guest on June-20-2021

Code answers related to "laravel select display selected value from database"

Browse Popular Code Answers by Language