Ozguru
Ozguru

Reputation: 29

POST request is always empty - Laravel 8

I am using PHP 8.0.7, Laravel 8.41.0 and new to Laravel. Building some simple APIs. No issues with GET APIs but having trouble with POST.

The $request object is always empty no matter what I did. It just returns [].

I am posting below data in Fiddler :

User-Agent: Fiddler
Content-Type: application/json

{
"parent_id" : "1",
"process_no" : "20",
"process_name" : "Aux Electrical",
"level" : "4",
"priority_no" : "1"
}

I tried to dump $request contents in api.php to no avail.

Route::post('/processtree', function (Request $request){
    return $request->all();
});

I tried all sorts of different versions of reading $request object, again did not work. All I get is [].

Any ideas what might be wrong here?

Upvotes: 2

Views: 663

Answers (1)

N69S
N69S

Reputation: 17204

Maybe reformat your json to a valid one (: instead of =) and without the line breaks

{"parent_id":"1","process_no":"20","process_name":"Aux Electrical","level":"4","priority_no":"1"}

Upvotes: 3

Related Questions