'Laravel Jetstream Livewire to Vue with Inertia Code Conversion
I've been following this awesome repository but I'm having a hard time converting this code (line 42 in the repo) to Vue with Inertia:
<select name="roles[]" id="roles" class="form-multiselect block rounded-md shadow-sm mt-1 block w-full" multiple="multiple">
@foreach($roles as $id => $role)
<option value="{{ $id }}"{{ in_array($id, old('roles', [])) ? ' selected' : '' }}>{{ $role }}</option>
@endforeach
</select>
Same code in the controller but for accessing the roles value in Vue, I have declared roles as props:
props: {
roles: Object,
},
Then for the select:
<select name="roles[]" id="roles" class="form-multiselect block rounded-md shadow-sm mt-1 block w-full" multiple="multiple">
<option v-for="role in roles" :key="role" :value="role">{{ role }}</option>
</select>
How do I set the selected attribute in the select input by getting the old values? Any help is much appreciated. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|