I use jquery, and just a suggestion, try a put request, it's worked for me.
PATCH ajax request not receiving any data from using multipart form data
Hi all, I have setup all the form, ajax header, @csrf and @method('PATCH') under form tag correctly, however i could not receive any input data from the form and i only received an empty array after i set
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
in ajax header. I have debugged through web browser debugger (network tab), if i dont set the headers, then i will receive CSRF token mismatch. When i added the headers then received an empty array with the use of $request->all(). When i changed the ajax type to "POST", its working.... But i want it to be PATCH request.
I have asked a question through laracast before but no luck still not working. Here is my previous question : https://laracasts.com/discuss/channels/laravel/how-to-fix-csrf-token-mismatch-for-patch-ajax-request-2nd-time
and similar situation i found in stackoverflow but no answer also : https://stackoverflow.com/questions/40656248/cannot-read-multipart-form-data-from-request-in-laravel
If you are using FormData then there is no need to include application/json header and you already specified @csrf in your form therefore FormData will also send that token so no need for X-CSRF-TOKEN header as well
And you need to send the request as POST and your laravel application will automatically get it as PATCH request because you included @method('PATCH') so your patch route and method for that route will get triggered
You could verify the method type in you controller method using this
$request->method()
Please or to participate in this conversation.