You may be wondering what’s the difference between query()
method and input()
method in Laravel. It’s mentioned straight away in the laravel docs.
While the input method retrieves values from the entire request payload (including the query string), the query method will only retrieve values from the query string:
The important aspects and the real difference between these methods are:
$request->input() – Will work with any HTTP verb( GET,POST etc)
$request->query() – Will work only with data passed from query string( GET method )
If you use a query string to pass the data, you will get the data on both methods. But if your data passed using POST, you won’t receive the posted data using query()
.
In other words, if you conside the native PHP example, it is:
$request->input()is the equivalent of $_REQUEST //this is either querystring or form-data submission.
$request->query() is just a straight forward $_GET //this is querystring
perfect