laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

$request in PUT route does not return input data #630

Closed zaherg closed 7 years ago

zaherg commented 7 years ago

First of all, I want to thanks everyone and am really sorry that I have started my conversation in the wrong place, this issue may not be a bug, it may be something am doing wrong and needs a correction from you guys to help me solve it.

Info

Description:

Am using Postman to send PUT request to my route, the body of my postman request is form-data and it has only one key options like in this image.

My route has the following:

    $app->put('/images/{imageId:[0-9]+}', [
        'as' => 'resizeAction',
        'uses' => 'ImagesController@resize'
    ]);

My controller has the following:

    public function resize($imageId, Request $request)
    {
        if (null !== $request->input('options')) {
            $options = json_decode($request->input('options'), true);
            return response()->json([
                'success' => true,
                'message' => 'You have passed',
            ]);
        }

        return response()->json([
           'success' => false, 'message' => 'You need to specify the options'
        ]);
    }

But for some reasons $request->input('options') will always be equal to null, there for my request fail as shown in this image. and if I dumped $request->all() I'll get an empty array.

now if I changed the body type to x-www-form-urlencoded it will work, but this will not allow me to send a file.

Steps To Reproduce:

I have recorded this video https://www.youtube.com/watch?v=SvvQ_YhU8JA and I think the whole code in the description above.

Thanks in advance.

zaherg commented 7 years ago

I did more testing today with xDebug to check and see if the request does contain any data when using PUT or not, and I found out it does not.

this is the link to the video I recorded https://youtu.be/jAz_3pOcYnU screen-shot-2017-07-11-12-03-39

thanks

zaherg commented 7 years ago

nevermind I just used PAW client and it worked. so clearly something going on with Postman or my end.

VeRJiL commented 6 years ago

Yoo Guys, I had this problem with PostMan when i was trying to send a PUT request to laravel api and i got null in $request and I find the solution and it is in the data format i was sending. I was sending form-data as body in order to update so that was the problem i just changed the form-data to raw and it fixed my problem and also i changed my header as: Content-Type : application/json

christhomas commented 5 years ago

For me it was because I imported the wrong Request object. I needed to import Illuminate\Http\Request and instead I accidentally imported Laravel\Lumen\Http\Request

malohtie commented 5 years ago

@christhomas You saved my day thanks