i want to change value from my dropdown but i’m begginer and i’m little lost.
This is my Controller method:
public function changeStatus(Request $request) { $lead = Lead::find($request->id); $lead = array( 'status_id' => $request->status_id ); Lead::whereId($request->id)->update($lead); return redirect()->back() ->with(['toast' => ['message' => 'Lead Status updated successfully !']]); }
This is my dropdown in vuejs file:
<select v-model="lead.status_id" @change="onChanges()" class="form-select form-control"> <option v-for="status in statuses" :value="status.id" :key="status.id" > {{ status.status_name }} </option> </select>
and this is my method in vue js:
onChanges(id,status_id) { this.$inertia.post( route("changestatus",{ id:id, status_id:status_id, }), ); },
the route is fine, the problem are probably my methods.
Advertisement
Answer
I think you should pass right values to your onChanges method. When you use @change=”onChanges()” you should call it with the same parameters as it was declared – id and status_id.
So it should be something like this
@change="onChanges(lead.id, $event)"
And in js
onChanges(id,event) { var status_id = event.target.value; this.$inertia.post( route("changestatus",{ id:id, status_id:status_id, }), );