1######## INSIDE LIVEWIRE COMPONENT
2public array $locationUsers = [];
3protected $listeners = ['locationUsersSelected'];
4
5public function locationUsersSelected($locationUsersValues)
6{
7 $this->locationUsers = $locationUsersValues;
8}
9
10######## INSIDE LIVEWIRE BLADE
11<div class="col-md-12 mb-3" wire:ignore>
12 <label for="locationUsers">Select Users</label>
13 <select id="locationUsers" class="form-control select2" multiple="multiple">
14 <option value="">--select--</option>
15 @foreach($this->users as $id => $name)
16 <option value="{{ $id }}">{{ $name }}</option>
17 @endforeach
18 </select>
19</div>
20
21######## INSIDE LIVEWIRE SCRIPTS
22document.addEventListener('livewire:load', function () {
23 $('#locationUsers').on('select2:select', (e) => {
24 @this.emit('locationUsersSelected', $('#locationUsers').select2('val'));
25 });
26
27 $('#locationUsers').val(@this.get('locationUsers')).trigger('change');
28});