#StackBounty: #laravel #postman Laravel doesn't get data from Postman

Bounty: 50

I am starting work on an API in Laravel, using Postman. However, no matter what I send via Postman, the $request received is empty.

Route in Laravel:

Route::group(['namespace' => 'Api', 'as' => 'api.'], function() {
    Route::post('/stock-list', 'DataController@stock_list');
});

Controller method:

public function stock_list(Request $request)
{
    logger()->info($request->all());
    return response()->json([
        'request' => $request
    ]);
}

The log shows that $request->all() is an empty array. Since I am also returning $request to Postman as a test, this is what Postman gets as a response:

{
    "request": {
        "attributes": {},
        "request": {},
        "query": {},
        "server": {},
        "files": {},
        "cookies": {},
        "headers": {}
    }
}

What am I sending? In Postman, I have this content in the body tab:

{
    'foo' : 'bar'
}

The body type is selected as raw and Postman reads it as JSON.

In terms of authentication, I have chosen basic auth with username and password for now, however I have not done anything on the Laravel side about this (as you can see from the route and controller). As far as I can tell, this shouldn’t matter at this point – the request should still be received by Laravel correctly, then either an "unauthenticated" response should be returned, or no authentication should happen at all since there is no auth middleware on the route.

Can someone explain the cause of the problem and suggest a solution?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.