Forum

I can not get inputs from a PUT/PATCH request

I am developing a rest api. I test it with Postman Rest Client. But I have had a headache with PUT and PATCH requests, the sent parameters can not be gotten in the controller with Input::get('param') neither Request::get('param') they always return NULL, I don't understand why. In the store method it works well. PD: I'm not using resourceful controllers (because I thought it could be the problem), I declared it with Route::put()

This is my controller, the store method works well: http://laravel.io/bin/bPb

And here is how I use postman: http://s13.postimg.org/4o0raxufr/postman.jpg

cesartc
cesartc
  • 3 years ago

How are you passing the parameters with Postman?
Please post some code.

This is my controller, the store method works well: http://laravel.io/bin/bPb And here is how I use postman: http://s13.postimg.org/4o0raxufr/postman.jpg

Laravel cheats with PUT/PATCH etc requests. These need to be POST requests with the extra POST variable '_method' set to the request type (e.g.) PUT.

http://laravel.com/docs/html#opening-a-form (read the read box in this section)

Enjoy!

Laravel cheats because html forms only support GET and POST, but it does understand a real PUT/PATCH request.

The problem looks like lies in Symfony it can't parse the data if it's multipart/form-data, as an alternative try using x-www-form-urlencoded content disposition.

Learn something new every day. cheers @tlgreg

well, finally I'm not sure about what happens, the put/patch requests go to the right controller method but the inputs couldn't be gotten. I had to use post requests instead of put/patch, breaking the REST best practices :c

Is there any update to this question?

I've also tried to use PUT/PATCH, here is the postman: http://screencast.com/t/BNY9sPAhlfrg

However the Input::all() is empty each time.

Any thoughts?

ok, it looks like in postman you should point that the data you send is 'x-www-url-formurlencoded'

Just wondering if this will be "fixed"? I realise you can add an extra form data element "_method" = "PATCH" while posting as POST verb but i'd prefer to just post with verb of PUT or PATCH.

Wow, thanks guys for figuring this out! I just spent about an hour trying to find out why my API wont work on PUT/PATCH. My issue was exactly the same with POST working fine but updates had an empty request body when testing via Postman.

I'm glad I finally found this thread and an answer after severely doubting my understanding of Laravel 5's routing and the new FormRequest validation.

I am having the exact same issue here. Is there any plans to get it fixed?

PavelPolyakov said:

ok, it looks like in postman you should point that the data you send is 'x-www-url-formurlencoded'

@canfiax Check this

IAmJulianAcosta said:

PavelPolyakov said:

ok, it looks like in postman you should point that the data you send is 'x-www-url-formurlencoded'

@canfiax Check this

Nice, thanks.

PavelPolyakov said:

ok, it looks like in postman you should point that the data you send is 'x-www-url-formurlencoded'

Thanks a lot

Anyone worked out how to get this working with PUT/PATCH and form-data? I need to submit files along with the request. For now I've fallen back to using a POST with the _method = PUT but would ideally like a nicer way of dealing with this.

POST and PUT use the URL-Params not the form data. Click on the "URL-Params" Button next to select method button.

multipart/form-data via PUT intentionally does not work in php: http://php.net/manual/en/features.file-upload.put-method.php

tlgreg said:

Laravel cheats because html forms only support GET and POST, but it does understand a real PUT/PATCH request.

The problem looks like lies in Symfony it can't parse the data if it's multipart/form-data, as an alternative try using x-www-form-urlencoded content disposition.

2 days of messing around trying to get it to work and this solved it, thanks!

PavelPolyakov said:

ok, it looks like in postman you should point that the data you send is 'x-www-url-formurlencoded'

It solved my problems. Thanks. Postman should has a tooltip or a simple introduction to guide us :D

EspadaV8 said:

Anyone worked out how to get this working with PUT/PATCH and form-data? I need to submit files along with the request. For now I've fallen back to using a POST with the _method = PUT but would ideally like a nicer way of dealing with this.

You are my 2nd saviour :d I don't know we could cheat POSTMAN by using that trick This is my case : - I want to use method PUT to upload file with POSTMAN. But if I point data to x-www-url-formurlencoded, it would not allow me to use File input. So in this case, with POSTMAN, I use POST, but with a _method input equal to PUT. It will allows me to PUT data with file (This trick only works with Laravel)