Tuesday, July 11, 2017

what is the difference between request()->json() and request()->input()

Asked by: jonte karlson


What is the difference between request()->json() and request()->input() in laravel:

is there any difference in functionality in laravel.


Answers

Answered by: Dj Detox at 2017-07-11 03:09PM



Basicaly they have a same funcionalty the only difference is at naming meaning when you see json you know that you are expecting json data while with input you can expecting jason data but also http request GET OR POST



Answered by: hardika satasiya at 2017-07-11 03:19PM



Both are almost same but having slight difference. Since $request->input() is smart enough to pull userdata from get, post or json. laravel offers $request->json(). there are 2 reasons you might prefer $request->json().

1) You might want to just be more explicit to other programmers on your project about where you're expecting the data to come from.

2) If POST doesn't have the correct application/json headers, $request->input() won't pick it up as JSON, but $request->json() will do.




Source

No comments:

Post a Comment

Adbox