Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rmobayen's avatar

Request $request vs. request()

Hi, everyone there are two approaches to access the requested values is there anything that makes either of them a better approach?

what is the difference(s) between them?

thanks!

0 likes
8 replies
Nakov's avatar

If you look at the implementation of the request() helper it essentially does the same :) it resolves the request from the Container. Which is the same as using Request $request in your controller method :) so there is no difference, use whichever is accessible to you at the moment :)

1 like
Snapey's avatar

helpers like request() are super useful but not liked by some as it couples your code too closely to the Laravel framework. They prefer to inject all dependencies into the class.

3 likes
rmobayen's avatar

thanks you right, that what I thought but wasnt sure!!

rmobayen's avatar

I wanted to know about it in general!! a) using the helper vs. b) inject the class explicitly

rmobayen's avatar

that is my concern. but I am not sure I understand what you are saying exactly! can you please explain a little bit more, please! or is there anywhere i can read about it?

thanks!

yasir306's avatar

The difference between these two is dependency injection.

As in $request, we are Injectiong the request class into our controller's function which has two benefits it creates loosely coupled code and it is also useful while writing tests for your application. While request() helper is causing tight coupling with your Laravel framework code which is not a good OOP approach.

Conclusion: Although they both do the same thing but you should prefer to use $request over request() helper as it is loosely coupled and hence facilitates writing tests.

3 likes

Please or to participate in this conversation.