Differences between query() and input() in Laravel?


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 will not receive the posted data using query().

In other words, if you consider 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


Editorial Staff

Editorial Staff at Tutsplanet is a dedicated team to write various tutorials about subjects like Programming, Technology and Operating Systems.

Reader Interactions

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Please enter your comment!
Please enter your name here