Level 1
Solution:
Blade
<h2 class="card-inside-title">Tags</h2>
<div class="form-group">
<select class="form-control" multiple="multiple" id="tags" name="tags[]">
@if(!empty($post))
@foreach($post->post_tags as $postTag)
<option selected="selected" value="{{$postTag->tag->id}}">{{$postTag->tag->tag_name}}</option>
@endforeach
@endif
</select>
</div>
JS
$('#tags').select2({
tags: true,
width: '100%',
tokenSeparators: [','],
ajax: {
url: '{{ url("getTagsSelect2") }}',
dataType: 'json',
data: function(params) {
return {
term: params.term
}
},
processResults: function (data, page) {
return {
results: data
};
},
}
});