0

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

Raheel Hasan
  • 5,753
  • 4
  • 39
  • 70
  • 1
    Might want to check out https://stackoverflow.com/a/27367330/583608 – Marshall Davis Aug 24 '17 at 02:37
  • 1
    Thanks @ToothlessRebel that helped. Now im using `\Request::instance()->request` instead of `\Request::input()` – Raheel Hasan Aug 24 '17 at 02:50
  • in fact, `\Request::instance()->request->all()` to get array – Raheel Hasan Aug 24 '17 at 02:56
  • 1
    It's php after all, so you can always use $_POST if don't want to call those weird functions :D – Maulik Aug 24 '17 at 02:57
  • its funny, if you look into `Illuminate\Http\Request` class, you can see the method `getInputSource()` which does the exact same thing, but its `protected`. On top of that, its pulled into the public method `input()` to get the input as both arrays of get and post ($input = `$this->getInputSource()->all() + $this->query->all()`). – Raheel Hasan Aug 24 '17 at 03:12

1 Answers1

0

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.

Marshall Davis
  • 3,337
  • 5
  • 39
  • 47