What is the difference between $request->get('name') and $request['name'] ?

  • the difference is that the built-in functions check the input data. Do not reinvent the wheel. And use ->input() - n.osennij
  • @ n.osennij what wheel?) I don’t see anything wrong with $request['name'] or $request->name . With this option, nothing prevents to check the data too (it works through __get ). But as far as source codes are visible in both cases, there is no verification, just access to the data. If we talk about the difference between input and dynamic properties, then input uses the data_get helper data_get which uses point notation, input is searched first in request, then in query, and in dynamic properties as I wrote in the answer: first, in request, then in parameters route. - Ilya Zelenko

1 answer 1

As far as I see, the documentation does not mention pro ->get(...) , but indicates ->input(...)

Here is what is written in the laravel source code:

This method belongs to Symfony HttpFoundation and is not usually needed when using Laravel.

And further:

Instead, you may use the "input" method.

In the documentation in the section Retrieving Input Via Dynamic Properties about the second method they write:

You may also have access to the Illuminate\Http\Request instance. When using dynamic properties If it is not present, it will be in the route parameters.