show your selected variable implementation
Receive data from axios post request in Controller
Hi guys, I think I misunderstood the post request with axios and I am starting to be a little bit frustrated about it.
I am trying to make a post request with axios. This is my case:
const formData = new FormData();
formData.append('category', selected);
axios.post('http://127.0.0.1:8000/cars', formData, {
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': token.content,
'X-Requested-With': 'XMLHttpRequest',
}
}).then(
response => console.log(response.data)
).catch(
error => console.log(error)
)
There's no problem with X-CSRF-Token, but with the data I receive in my controller. The variable "selected" represents a text of the selected option. However when I dd($request->all()) in my controller, field 'category' don't hold the text, but the numeric value of the selected option. I am trying everything but it seems like I miss something.
It kinda looks like I can pass any data in axios post, it is just ignored and the controller requests for the exact values from the template, not from my post request.
If anybody has an idea what's the matter, please, let me know. Thanks in advance.
Please or to participate in this conversation.