I am using laravel 5.0. How do I get the user agent from $request in a controller ?
public function index(Request $request) { $useragent = $request->userAgent; // ???? return $useragent; }
In this snippet, we'll see how to get user-agent from user request in laravel. $agent = $request->header('user-agent'); $agent = request()->header('user-agent'); $agent = Request::header('user-agent'); All of these code snippet return the User-agent in Laravel.
Getting the Browser 1$browser = Agent::browser(); In my particular use case, when I make the request, $browser is equal to Firefox . You can also find out the browser version by passing the result of Agent::browser() to the version() method like so: 1$browser = Agent::browser();
You can use either of following ways:
$ua = $request->server('HTTP_USER_AGENT'); $ua = $request->header('User-Agent');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With