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!
Is the body payload is not allowed in laravel PUT requests? Or how we send additional data in a PUT request?
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.
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.
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.
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.
Just change from form-data
to x-www-form-urlencoded
:
If 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.
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!
you are passing form-data instead you need to check x-www-form-urlencoded in post-man.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With