Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel-4 Empty PUT data being sent to a resourceful controller

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.

like image 412
Yasha Nisanov Avatar asked May 30 '13 01:05

Yasha Nisanov


2 Answers

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.

like image 141
lo_fye Avatar answered Nov 08 '22 02:11

lo_fye


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

like image 2
Blackus Avatar answered Nov 08 '22 02:11

Blackus