7

G'day,

I'm having issues with PUT requests made via Chrome Postman to a controller, the PUT data is not present, POST data works fine.

I had performed a composer update prior to ensure that the latest version of vendor products where available and even removed bootstrap/compiled.php.

Is anybody else having similar issues?

The update function with both section_id and data being empty in the response:

public function update($id)
{
    $section_id = Input::get('section_id');

    $data = Input::all();

    return Response::json(array('id' => $id, 'section_id' => $section_id, 'data' => $data));
}

I've debugged the code all the way to ParameterBag.php and $this->request's parameter list is empty, I'm not sure what's supposed to contain any values but all through the code the input values are empty. Not sure what to do now, short of using post instead of put.

Phill Sparks
  • 20,000
  • 3
  • 33
  • 46
Yasha Nisanov
  • 178
  • 3
  • 10
  • 1
    I'm all about RESTful, but I haven't yet committed myself to PUT, since I hear it's not accepted everywhere? And it seems a little bloated to have a POST-parameter fallback in addition. So I'm thinking of going with the POST-parameter from the get go on my next app: http://stackoverflow.com/questions/4994827/what-alternative-is-advised-when-a-client-cant-make-a-put-delete-request I mentioned it because maybe dropping the PUT is your answer? – prograhammer May 30 '13 at 01:41
  • What do you have on var_dump(Input::all())? – Antonio Carlos Ribeiro May 30 '13 at 03:42
  • An empty array: array(0) {} an array the contains the following when submitted via the POST resource endpoint: array(2) { ["compilation_id"]=> string(1) "1" ["section_id"]=> string(1) "1" } – Yasha Nisanov May 30 '13 at 04:49
  • Are you using `
    `? You should use `Form::open(array('url' => 'foo/bar', 'method' => 'put'))`, because most browsers still doesn't understand PUT verb so Laravel will add a hidden `'_method'="PUT"` to control this for you.
    – Antonio Carlos Ribeiro May 30 '13 at 05:36
  • 2
    Have you tried submitting to somewhere like http://requestb.in and inspecting the headers and payload? Have you tried making the same request using [curl](http://curl.haxx.se/) from the command line? – Phill Sparks May 30 '13 at 07:38
  • I just performed a phpunit test using the DOM crawler and the PUT data was present as expected so somehow; Chrome Postman doesn't delivery PUT data as expected. I'm just going to fallback to the POST method since my purposes warrant both create and update processes in the single delivery request and POST is less browser dependant, I would've had to use one of the other anyway. Thanks!! – Yasha Nisanov May 30 '13 at 23:29

2 Answers2

9

PUT parameters don't work "out of the box" because PHP itself has some security restrictions around them. See: http://www.php.net/manual/en/features.file-upload.put-method.php

Laravel does implement a common workaround for this, though.

In Postman (or your form, or curl, or whatever client you're using), simply add a URL parameter name: "_method" value: PUT

Example 1: ?_method=PUT

Example 2: <input type="hidden" name="_method" value="PUT" />

Laravel uses the symfony Http Foundation which checks for the _method variable and if it's present it routes based on its value, instead of the actual HTTP method used.

lo_fye
  • 6,790
  • 4
  • 33
  • 49
2

You have to send a POST request with adding an extra parameter _method with value PUT and it will works fine.

Blackus
  • 6,883
  • 5
  • 40
  • 51