Laravel 5只能从请求获得GET或POST参数

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.

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.

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.

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