Lumen-framework: $request in PUT route does not return input data

Created on 10 Jul 2017  路  5Comments  路  Source: laravel/lumen-framework

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

  • Lumen Version:
    Lumen (5.4.6) (Laravel Components 5.4.*)
  • PHP Version:
    php-7.1
  • Database Driver & Version:
    MySQL mysql:5.7

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.

Most helpful comment

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

All 5 comments

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

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

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

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

@christhomas You saved my day thanks

Was this page helpful?
0 / 5 - 0 ratings