Ad
Axios Patch Request Not Working With Laravel
I'm trying to make a patch request from axios, but the data is not being sent.
const url = route('industries::update',id)
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
return axios.patch(url,data,{ headers })
the data parameter is "FormData()"
I've also tried appending the key method with _PATCH in the form data
let formData = new FormData()
formData.append('method','_PATCH')
But nothing seems to work. I get the default laravel's 422 error from the responses (that the values are required).
Ad
Answer
1st. Your data is an instance of FormData
but your header is application/x-www-form-urlencoded
which is wrong, use multipart/form-data
instead. However, it will be set automatically when you use instance of FormData
as data.
2nd. Send request via axios.post
and append _method: PATCH
to your formData
:
const url = route('industries::update', id)
/*
const headers = {
'Content-Type': ' multipart/form-data' // <= instead of `application/x-www-form-urlencoded`
}
*/
return axios.post(url, data) // <= instead of `axios.patch` and omit unnecessary `headers`
And:
let formData = new FormData()
formData.append('_method', 'PATCH') // <= instead of `('method', '_PATCH')`
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad