Laravel Request input() or get()
Injection vs Facade
In controller method Request injection functionality is always preferable, because in some methods it could help you to use Form Requests (they are extending default Request class) validation, that will validate your request automatically just before entering to the actual controller method. This is an awesome feature that helps to create slim and clean controller's code.
Using default Request injection makes your controller's methods similar and easier to maintain.
Also object injection is always better than Facades, because such methods & objects are easier to test.
get vs input
get(...)
andinput(...)
are methods of different classes:
- First one is method of Symfony HttpFoundation Request,
-
input()
is a method of the Laravel Request class that is extending Symfony Request class, and it supports dot notation to access nested data (like$name = $request->input('products.0.name')
).