I have a small problem. I have a Select2 multiselect field in my edit form. Now my goal is that my script loads all options and that the correct options are preselected.
I have already tried the whole thing, but so far it has not led to the desired result
Here is my Code
Controller snippet for the multiselect.
// Convert multiselect in right form
$product = $product['tags'];
$new = serialize($user);
$product['tags'] = $new;
edit.blade.php (snippet)
<div class="form-group">
<label for="tag">Product Tags</label>
<select id="tag" class="select2 select2-hidden-accessible {{ $errors->has('tags') ? 'error' : '' }}" multiple="multiple" name="tags[]" style="width: 100%;" data-select2-id="5" tabindex="-1" aria-hidden="true" value="1">
@foreach($tags as $tag)
<option value="{{ $tag->id }}" {{ in_array($tag->id, $prisoner->tag) ? 'selected="selected"' : '' }}>{{ $tag->label }} - {{ $tag->name }}</option>
@endif
@endforeach
</select>
</div>
small js code:
$('#tag').select2({ placeholder: "Please select" }).trigger('change');
I hope someone can help me.