32

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

2
  • 1
    Simply, Request::input('field'). Commented Jul 12, 2016 at 3:53
  • @IsmailRBOUH input is not a static method
    – xelber
    Commented Jul 12, 2016 at 21:43

3 Answers 3

76

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

2
  • 5
    This doesn't work in lumen :/ You have to use app()->request. Look Helpers.php Commented Nov 21, 2019 at 22:03
  • this is sooooo useful for me to know! [+1]
    – kapitan
    Commented Jun 30, 2022 at 0:33
4

Lumen doesn't have this Helper "request()".

You must use like this:

app()->request->field_name
3

What worked out for me is:

request('field_name')

Reference: https://laravel.com/docs/9.x/helpers#method-request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.