Sending data to the server for updating using the PUT method. The data is sent using FormData. The data is sent, it is visible in Chrome, but the server does not see the data.

$request = $request->all() 

With the POST method, everything works fine. Sending text data and file

How do I update the data? Redo routes under the POST method?

UPD

In Controller, I meanwhile, just trying to get a response from the server

 public function update(Request $request, $id) { $request = $request->all(); dd($request); } 

This method works if you send data in POST format, then everything works fine. I use instead of vue-resource axios

 save() { var vm = this var form = document.querySelector('form'); var formdata = new FormData(form) axios[this.method](this.store, formdata) .then(function (response) { if (response.data.saved) { vm.$router.push(vm.redirect) } }) .catch(function (error) { console.log(error) }) } 

By the way, if I write $reqyest->getContent() , then I will receive the data in this format, but how can I process it?

 b""" ------WebKitFormBoundaryFEIpstOEw72VwaAe\r\n Content-Disposition: form-data; name="name"\r\n \r\n Moscow\r\n ------WebKitFormBoundaryFEIpstOEw72VwaAe\r\n Content-Disposition: form-data; name="cost"\r\n \r\n 1.00\r\n ------WebKitFormBoundaryFEIpstOEw72VwaAe\r\n Content-Disposition: form-data; name="picture"; filename="angel.png"\r\n Content-Type: image/png\r\n \r\n ...HIDEN... ------WebKitFormBoundaryFEIpstOEw72VwaAe\r\n Content-Disposition: form-data; name="description"\r\n \r\n <p>1</p>\r\n \r\n ------WebKitFormBoundaryFEIpstOEw72VwaAe--\r\n """ 
  • Give an example of your routes and controllers and still do php artisan route: list, see if you have a route - Orange_shadow
  • @Orange_shadow, The route is Route :: group (['prefix' => 'api /'], function () {Route :: resource ('basket', 'BasketController'); Route :: resource ('city', ' CityController ');}); - blanry
  • and further? How do you process in the controller? , and it is advisable to make changes to the question, and still you ask this question in the routes / web.php file do you pass tocken? What is the response from the server? - Orange_shadow
  • And another question is if you use vue.js then you also use vue resource or not? - Orange_shadow
  • @Orange_shadow, updated - blanry

1 answer 1

So we have: FormData data should be sent by post method, but added to the form

 <input name="_method" type="hidden" value="PUT"> 

or before sending do so

 formData = new FormData(form) formData.append("_method", "PUT");