Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lumen access Request object outside controller

Tags:

php

laravel

lumen

I am creating a custom guard where I need to access the Request object in order to get http headers. I have tried request() but it is undefined in lumen.

How do I get access to Request object outside of an controller class?

Note: Not a duplicate of Laravel access request object outside controller

like image 679
Sisir Avatar asked Sep 01 '17 21:09

Sisir


1 Answers

I've never used Lumen myself but you should be able to resolve the current request from the Service Container:

app('request');

You might have to pass the full class name:

app('Illuminate\Http\Request');
like image 55
Thomas Avatar answered Oct 11 '22 13:10

Thomas