Just syntax difference.
Feb 11, 2022
15
Level 1
whats diffrence between $request->name and $request->input(name)
hello every one, it was question for me whats the difference between the $request->name and $request->input('name') ? must we use the second for insert from forms ?
Level 122
$request->name is a convenient shortcut, but the input method has advantages in some cases.
-
when the form input includes a dash, eg
full-name. It is not possible to access$request->full-namebut$request->input('full-name')will not complain about the dash -
$request->input() method allows a fallback to be specified if the field is missing from the request, eg
$request->input('type','invoice') -
when dealing with arrays, in the input, you can use dot to dig into the request, eg
$request->input('products.0.name');
4 likes
Please or to participate in this conversation.