Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No body data found in Laravel 5.3 with PUT request

Here is my route to update the contacts.

Route::put( 'contact-type/{id}', 'ContactTypeController@update' );

Here is the controller to test if the request was there with the PUT request.

public function update(Request $request, $id)
{
    return response()->json([ 'id' => $id, 'req' => $request->all() ]);
}

When i send a request using postman, the request is null!

enter image description here

Is the body payload is not allowed in laravel PUT requests? Or how we send additional data in a PUT request?

like image 759
rakibtg Avatar asked Oct 24 '16 05:10

rakibtg


People also ask

Can a PUT request have no body?

A PUT request sends data to the server using the same URI as a GET request. It also has an optional body. If there is no body, then the request is considered successful. However, if there is a body, then the request fails because the server expects a different type of response.

How do you pass data in put method?

You can send data to the server in the body of the HTTP PUT request. The type and size of data are not limited. But you must specify the data type in the Content-Type header and the data size in the Content-Length header fields. You can also post data to the server using URL parameters with a PUT request.

What is $request in laravel?

Laravel's Illuminate\Http\Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, cookies, and files that were submitted with the request.

How can you retrieve the full URL for the incoming request in laravel?

The “path” method is used to retrieve the requested URI. The is method is used to retrieve the requested URI which matches the particular pattern specified in the argument of the method. To get the full URL, we can use the url method.


4 Answers

Just change from form-data to x-www-form-urlencoded:

Postman body options

like image 137
Beginner Avatar answered Nov 03 '22 08:11

Beginner


enter image description hereIf you had to use form-data (to upload images) as file input doesn't exists in x-www-form-urlencode

you can send a POST-Request and add a field with the name _method and the value PUT or PATCH to the request body.

like image 42
M.abdelrhman Avatar answered Nov 03 '22 09:11

M.abdelrhman


You need to add the appropriate Content-Type header for your data.

Click x-www-form-control this should add the appropriate header.

Hope this helps!

like image 21
Rwd Avatar answered Nov 03 '22 08:11

Rwd


you are passing form-data instead you need to check x-www-form-urlencoded in post-man.

like image 1
MH Fuad Avatar answered Nov 03 '22 08:11

MH Fuad