Search code examples
phplaravelapilumen

Laravel Get Body request and avoid Query string params


How to get body request parameters without the query string parameters in POST method.

when I used $request->all() it always returns all parameters including the Query string.

I have my own reason that's why I did not use $request->only([]) or $request->except([]). (cause I want to create a global function)

I want to get the body request parameters only... How to do that?


Solution

  • Similarly to how there is access to the query string via $request->query() there is access to the Request payload via $request->post(). These methods are accessing $request->query and $request->request Parameter Bags.

    Both methods query() and post() have method signatures that allow you to pass a key to retrieve and a default value as well: $key = null, $default = null