Laravel access request object outside controller
Asked Answered
O

3

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

Osswald answered 12/7, 2016 at 3:46 Comment(2)
Simply, Request::input('field').Aberration
@IsmailRBOUH input is not a static methodOsswald
P
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

Patriliny answered 12/7, 2016 at 4:15 Comment(2)
This doesn't work in lumen :/ You have to use app()->request. Look Helpers.phpCorny
this is sooooo useful for me to know! [+1]Tum
P
4

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

You must use like this:

app()->request->field_name
Packer answered 18/10, 2023 at 17:41 Comment(0)
T
2

What worked out for me is:

request('field_name')

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

Tzar answered 26/6 at 11:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.