Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stephan-v's avatar

Why does Laravel not allow access to get parameters with a post request?

I have been checking out the Laravel source code a bit and I found this bit of code:

return $this->getRealMethod() == 'GET' ? $this->query : $this->request;

From:

https://github.com/illuminate/http/blob/master/Request.php#L668

This basically specifies that if the request method for a request is a 'GET' that the input method returns the query string parameters and otherwise gives you access to the POST variables.

This means that whenever I would make a post request I can not do the following to get a query string parameter named "date" for example:

$request->input('date')

I know it is useful to not merge POST and GET data since you get the possibility of overriding them but what is the exact motivation behind not allowing a user access to the query parameters when you make a POST request?

The way I see it, the input could have been split up into postInput and getInput for example to allow access to both without merging them. Of course you lose the ability that a generic input method gives you, but you gain a lot of flexibility.

Any thoughts on this?

0 likes
2 replies
ejdelmonico's avatar

I believe it is written in that manner to handle other types of requests. Like PUT and DELETE because you use a hidden input for those two with a POST method.

/**
     * Gets the request "intended" method.
     *
     * If the X-HTTP-Method-Override header is set, and if the method is a POST,
     * then it is used to determine the "real" intended HTTP method.
     *
     * The _method request parameter can also be used to determine the HTTP method,
     * but only if enableHttpMethodParameterOverride() has been called.
     *
     * The method is always an uppercased string.
     *
     * @return string The request method
     *
     * @see getRealMethod()
     */
    public function getMethod()
    {
        if (null === $this->method) {
            $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));

            if ('POST' === $this->method) {
                if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
                    $this->method = strtoupper($method);
                } elseif (self::$httpMethodParameterOverride) {
                    $this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
                }
            }
        }

        return $this->method;
    }

    /**
     * Gets the "real" request method.
     *
     * @return string The request method
     *
     * @see getMethod()
     */
    public function getRealMethod()
    {
        return strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
    }

You are able to get all request data with $request->all() no matter which method you choose.

jekinney's avatar

Been a long time sense I used input, but I thought now it's only for static method.

Any case as was stated above, the typical use case of get: you define the params in your route file (/url/{data}) and post request you assess via the Request object. ($request->date).

Maybe your overthinking?

Please or to participate in this conversation.