How to get data passed from PUT method

13,801

Solution 1

You are getting empty response because PHP have some security restrictions against PUT. But Laravel have a workaround for this.
So, to solve this you have to send a POST request from Postman instead, with a POST param _method with value PUT. And that should work.

Solution 2

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.

Solution 3

public function putUpdate(Request $request, $id){

print_r($request->all()); exit;

}

And change route too,

Route::put('vehicletypes/{id}','API\VehicletypeController@putUpdate');

Solution 4

Checked "x-www-form-urlencoded" instead of "form-data" under body tab in the Postman, the put methood will work as well...

Share:
13,801
Karthik
Author by

Karthik

Updated on June 27, 2022

Comments

  • Karthik
    Karthik almost 2 years

    I am creating an API for Laravel. I use the PUT method for updating data.

    I send data with Postman using the PUT method. In my controller, I got an empty array. How to access the passed data?

    In my route, I have:

    Route::put('vehicletypes/{id}','API\VehicletypeController@update');
    

    In my controller:

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

    enter image description here

    How to get the data passed in PUT method?

  • Himanshu Upadhyay
    Himanshu Upadhyay over 6 years
    As I said earlier, just try x-www-form-urlencoded
  • Ghassen Louhaichi
    Ghassen Louhaichi over 6 years
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
  • lagbox
    lagbox over 6 years
    @GhassenLouhaichi how so? try using x-www-form-urlencoded ... seems to be an answer to me
  • Ghassen Louhaichi
    Ghassen Louhaichi over 6 years
    Your response is more of a suggestion than an answer, I suggest updating your post to explain exactly and with code how to "try using x-www-form-urlencoded..." as you suggested.