8

I can access request params using Request::input() or Request::all().

The problem is that my request includes both GET and POST params, but only GET ones are used to calculate signature.

Is there a way to retrieve only a set of GET or a set of POST params from request in Laravel 5.1?

Or going with $_GET and $_POST is my only option here?

Thank you.

MaGnetas
  • 4,918
  • 4
  • 32
  • 52

3 Answers3

7

You can use Request::query() to get only GET parameters. Keep in mind that there are no guaranties about consistency in the order of parameters you get from GET, so you might need to sort the array before calculating the signature - depending on how you calculate the signature.

jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
  • 2
    it's fine, params are sorted in signature checking method. let me check that once I get back to my mac. any ideas on extracting only POST params? – MaGnetas Jul 23 '15 at 11:25
  • Yep. Request::query() works perfectly. Thanks a lot. – MaGnetas Jul 23 '15 at 11:29
5

If you need something straightforward you can just use the global helper:

$pathData = request()->path(); <br />
$queryData = request()->query(); <br />
$postData = array_diff(request()->all(), request()->query());

https://laravel.com/docs/5.6/requests

Sven Hakvoort
  • 3,543
  • 2
  • 17
  • 34
aamuller
  • 55
  • 1
  • 4
2

Follow these instructions to extend the Laravel Request class with your own:

https://stackoverflow.com/a/30840179/517371

Then, in your own Request class, copy the input() method from Illuminate\Http\Request and remove + $this->query->all():

public function input($key = null, $default = null)
{
    $input = $this->getInputSource()->all();

    return data_get($input, $key, $default);
}

Bingo! Now in a POST request, Request::query() returns the query (URL) parameters, while Request::input() only returns parameters from the form / multipart / JSON / whatever input source.

Community
  • 1
  • 1
Tobia
  • 17,856
  • 6
  • 74
  • 93
  • 1
    I don't get why getting post, get, query variables should be a pain! Laravel utilizes a lot of packages, creates its own wrapper over them and still sucks! – hpaknia Oct 12 '16 at 23:19