When I post to my API endpoint with postman or my application the request parameter is an empty array.
With other controllers post requests work fine and the request param gets handled well. Only with my order controller does my post body not get processed.
I haven't made any changes and reverting to an older commit also did not help.
I'm at the point where I have no clue why it doesn't accept the JSON body.
Controller
public function createOrder(Request $request)
{
return $request->product_id;
}
POST body | Raw JSON
{
"product_id": 4
}
Response response is an empty array []"
I've tried to print the $request and I got this as response
POST /api/order/post HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, br
Authorization: Bearer.{token}
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 20
Content-Type:
Cookie: XSRF-TOKEN={Token}%3D%3D; laravel_session=%3D%3D
Host: backend.host
User-Agent: PostmanRuntime/7.22.0
Cookie: XSRF-TOKEN==={token}; laravel_session={Token}
{
"product_id": 4
}
My post body is visible then so I'm confused why it's not showing
What I expect and what I get
I expect the request to return the value of my JSON body
what is happening nothing is returned
note: I've recently added passport, but it was working fine last time I used this endpoint after adding laravel
Working controller
public function store(Request $request)
{
return $request;
}
Api routes
Route::post('order/create', 'OrderController@createOrder');
Route::post('product/create', 'ProductController@store');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire