Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get useragent in controller laravel 5 php

Tags:

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; } 
like image 281
Momo Avatar asked Mar 28 '16 17:03

Momo


People also ask

How do I get Useragent in laravel?

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.

How do I get browser information 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();


1 Answers

You can use either of following ways:

$ua = $request->server('HTTP_USER_AGENT');  $ua = $request->header('User-Agent'); 
like image 193
thanhpk Avatar answered Sep 17 '22 14:09

thanhpk