I have a problem with multiple select in laravel using illuminate html, I want to pre-select items, it works when I put them manuelly with an array like this :
{!! Form::select('tags_list[]', $tags, [2, 3], ['class' => 'form-control', 'multiple' => true]) !!}
But when I use a model to put the list, like this :
{!! Form::select('tags_list[]', $tags, $post->tags_list, ['class' => 'form-control', 'multiple' => true]) !!}
It doesn't work and I checked the list is returned correctly, here is the result of :
dd($post->tags_list);
Collection {#273 ▼
#items: array:2 [▼
0 => 1
1 => 2
]
}
And here is the method that return the tags_list
public function getTagsListAttribute()
{
return $this->tags->lists('id');
}
I am new in Laravel framework, can anyone help me with this issue, thanks in advance
<div class="form-group">
{!! Form::labelControl('user_type','User Type'),['class'=>'control-label col-md-2'], TRUE ) !!}
<div class="col-md-3">
{!! Form::select('user_type[]', $selected_users, null, ['id'=>'user_type','multiple'=>'multiple','multiselect'=>'multiselect','class'=>'form-control']) !!}
</div>
</div>
<script>
$(document).ready(function () {
$("#user_type").multiselect();
});
</script>
Things to remember:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.