Laravel Get Browser Info Example

10-Apr-2023

.

Admin

Hi Guys

Today, I will explain you can how to get browser information in laravel. we will get browser name, version name. We will show simple example of get browser information.

We will jenssegers package using get browser information. All the information you need to know about user are accessible by using Agent (jenssegers/agent) package.Agent utilizes the Mobile Detect PHP Class under the hood. Agent makes Laravel equipped to detect the user environment.We will detecting user browser and its version using the jenssegers package.

Here i give you full example of ajax pagination example step by step like create laravel 7/6 project ,route,controller file etc. So you have to just follow few steps.

Install jenssegers/agent Package


here in this step the jenssegers/agent Package

composer require jenssegers/agent

Add providers and aliases

After the install package add providers and aliases in the "config/app.php" file.

following path: config/app.php

'providers' => [

....

Jenssegers\Agent\AgentServiceProvider::class,

],

'aliases' => [

....

'Agent' => Jenssegers\Agent\Facades\Agent::class,

]

After the following method to get browser information.

Get Browser Name

here the controller in get user browser name of a Chrome, IE, Safari, Firefox,etc

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$agent = new Agent();

$browser = $agent->browser();

dd($browser);

}

Output

"Chrome"

Get Browser version

now the controller in get user browser version.

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$agent = new Agent();

$browser = $agent->browser();

$version = $agent->version($browser);

dd($version);

}

Output

"79.0.3945.130"

Get User language

now the controller in get user browser language of 'nl-nl', 'nl', 'en-us', 'en',etc.

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$agent = new Agent();

$languages = $agent->languages();

dd($languages);

}

Output

array:4 [

0 => "en-us"

1 => "en"

2 => "la"

3 => "gu"

]

Get Platform

here the controller in get user platform of a Ubuntu, Windows, OS X,etc

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$agent = new Agent();

$platform = $agent->platform();

dd($platform);

}

Output

"Windows"

Get Platform Version

here the controller in get user Platform version,

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$agent = new Agent();

$platform = $agent->platform();

$version = $agent->version($platform);

dd($version);

}

Output

"10.0"

It will help you...

#Laravel 7

#Laravel

#Laravel 6