Search code examples
phppostlaravel-5.3

Laravel 5.3 - POST is polluted with GET values


back in the (real) days, we used to use $_GET, $_POST! and now we got Laravel's \Request::input(). Consequently here is whats happening:

if(\Request::isMethod('post'))
{
    $POST = \Request::input();
}

if I have the a variable in $_GET, the value gets in the POST as well.

For example:

&x=1 //i.e. in the query string

$_POST['x'] = null; //as it was not posted with the form, but it could be as there is a field with same name

$POST['x'] = 1; //as its in the GET, but should be null as its not in the $_POST!

Any solution to get POSTed vars only? Or shall I just use $_POST?

Thanks


Solution

  • I believe the only way to get this from the Request instance is to access either the query (GET) or request (POST) property. These are both ParameterBag instances, so you'll probably use the ->get() method of them to access the parameter you want.