Replace method from Request facade not replacing data from query parameters #31683
Environment:
Laravel Version: 6.8 (Replace method is actually the same in version 7 also)
PHP Version: 7.2
Database Driver & Version: pgsql & Postgre 9.6
Description:
The replace method from the Request facade is not replacing data from query parameters.
The documentation of the method says "Replace the input for the current request.".
I would assume that input would mean "all input", not just the input from the form.
In addition, if one call the method "input" from the Request facade, the data from (body) both form and query will be returned, making me think that the replace method would touch both of them.
Steps To Reproduce:
Try making two PUT requests. One where parameter "test" is sent via form and one where the "test" parameter is sent via query.
Using the following code
Request::replace(Request::except(['test']));
the parameter "test" will be only replaced if it is sent via form, but not if sent as query parameter.
Has anybody run into this problem?
I tried opening an issue on Github, but they wanted to confirm that it is an issue first.
You can only use replace on query parameters whenever you do a GET request. If you do a POST request you can only do a replace on the input fields itself
public function replace(array $input)
{
$this->getInputSource()->replace($input);
return $this;
}
protected function getInputSource()
{
if ($this->isJson()) {
return $this->json();
}
return in_array($this->getRealMethod(), ['GET', 'HEAD']) ? $this->query : $this->request;
}
$this->query points to the query parameters in the URL. $this->requests points to the body from the request.
No, its not a problem on my side, I am saying that this might be wrong or there should to be additional replace method to replace from both query and body parameters no meter what HTTP method is used.
I disagree with you. But let's say that this behavior is as expected, additional method for replacing from both query and body parameters would not hurt anybody.