What have you tried so far?
Listing data from my database in my view - Inertia
How can I get my data listed in my view in a select option, so my user can pick something that is in my database? I am using Inertia
@tykus For this project with Inertia nothing, to be honest, I'm stuck : ) I was searching for a way on https://inertiajs.com/ ,but without any luck.
@TikTina you need to return the data whenever you render the Vue component using Inertia:
return \Inertia\Inertia::render('YourPage', [
'options' => YourModel::pluck('name', 'id'),
// ...
]);
Now, in the Vue Component template you iterate over the options
<select v-model="selectedOption">
<option v-for="(name, id) in options" :key="id" :value="id">{{ name }}</option>
</select>
public function getData (){
return \Inertia\Inertia::render('SymptomsQuestionnaire', [
'options' => Symptom::pluck('symptom', 'id'),
<option v-for="symptom, id in options" :key="id" :value="id">{{ name }}>Low</option>
So like this, but I'm getting and error for this comma after symptom in option...
@tiktina wrap the value and key in parentheses
<option v-for="(symptom, id) in options" :key="id" :value="id">{{ name }}>Low</option>
@tykus It's still not rendering :/
@TikTina what are you getting; any errors in the console?
@tykus Like this, I tried it on the middle one: https://imgur.com/a/gomQtqV
@TikTina any errors in the console?
Can you check the content of the Response also?
@tykus No errors, but shouldn't I use my Controller instead of Model?
@TikTina what do you mean by:
shouldn't I use my Controller instead of Model?
I meant the Response in the Network tab in the Browser... are the options in the props?
@tykus So all the code I need is in my Symptom Model, and SymptomQuestionnaire.vue, I don't need to use my SymptomQuestionnaireController to fetch my data? No, nothing is showing in the Response
@TikTina I just want to know what data is being sent to the Vue component using Inertia
@tykus I am really sorry, I don't understand you. I just want to fetch data from the database.
@TikTina in the browser; open your network tab in the dev tools (probably CTRL+SHIFT+C) - in the Network tab you can click on the Request to your endpoint - you will see there the Response payload.
@tykus https://imgur.com/a/Lu75Jxc I can't see anything.
@TikTina The requests are filtered for Manifest; pick XHR or All instead
Please or to participate in this conversation.