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

Posted on

You might be wondering what is the difference between query() method and input() method in Laravel. It’s mentioned right away in the laravel docs.

While the input method fetches values ​​from the entire query payload (including the query string), the query method fetches only the 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, SEND etc)

$request->request() – Will only work with data passed from the query string ( OBTAIN method )

If you use a query string to pass the data, you will get the data on both methods. But if your data was transmitted using POST, you will not receive the data posted using query().

In other words, if you consider the native PHP example, it’s:

$request->input()is the equivalent of $_REQUEST // this is either a query string or form data submission.

$request->request() is just a simple $_GET // it’s a query string


Editorial team

The Tutsplanet Editorial Team is a team dedicated to writing various tutorials on topics such as programming, technology, and operating systems.

Interactions with the reader

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

Leave a Reply

Your email address will not be published.