According to the Laravel documentation Request is acquired via dependency injection. For a controller this is fine, but how do we access Request object outside a controller, for example in a view
3 Answers
There is request helper in laravel. You can use Request Object anywhere. For example
request()->field_name
Here's laravel documentation link for request helper https://laravel.com/docs/5.2/helpers#method-request
-
5This doesn't work in lumen :/ You have to use
app()->request
. Look Helpers.php Commented Nov 21, 2019 at 22:03 -
Lumen doesn't have this Helper "request()".
You must use like this:
app()->request->field_name
What worked out for me is:
request('field_name')
Reference: https://laravel.com/docs/9.x/helpers#method-request
Request::input('field')
.