I am working on a project in which I pass a list of concerns and a list of client concerns. I am trying to check all concerns that have matching client concerns in the edit view. The idea here is that I can have a list of all possible concerns and have the client's concerns pre-checked. However I can't seem to get it working. The below code is what I am using, but this just creates 4 copies of the concerns list. Any assistance would be appreciated.
ClientController.php
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Client $client
* @return \Illuminate\Http\Response
*/
public function edit(Client $client)
{
//
$concerns = Concern::all();
return Inertia::render('Client/Edit',
[
'client' => $client::with('concerns')->get()->first(),
'concerns' => $concerns,
]
);
}
Client/Edit.Vue
<ul id="concerns">
<li v-for="(concern,id) in concerns" v-bind:key="id">
<span v-for="(cc, id) in client.concerns" v-bind:key="id">
<span v-if="concern.id === cc.id">
<input type="checkbox" :name="concern.concern_slug" :value="concern.id" v-model="form.concerns" checked />
<label :for="concern.concern">{{ concern.concern }}</label>
</span>
<span v-if="concern.id !== cc.id">
<input type="checkbox" :name="concern.concern_slug" :value="concern.id" v-model="form.concerns" />
<label :for="concern.concern">{{ concern.concern }}</label>
</span>
</span>
</li>
</ul>
...
<script>
import BreezeAuthenticatedLayout from '@/Layouts/Authenticated.vue'
import BreezeCheckbox from '@/Components/Checkbox.vue'
import { Head } from '@inertiajs/inertia-vue3';
import VueGoogleAutocomplete from 'vue-google-autocomplete'
export default {
props: {
errors: Object,
concerns: Object,
client: Object,
clientConcerns: Object,
},
data () {
return {
form: {
first_name: this.client.first_name,
last_name: this.client.last_name,
email: this.client.email,
address: this.client.address,
city: this.client.city,
postal_code: this.client.postal_code,
province: this.client.province,
preferred_day: this.client.preferred_day,
preferred_time: this.client.preferred_time,
preferred_frequency: this.client.preferred_frequency,
goals: this.client.goals,
concerns: [],
},
}
},
...
</script>