Laravel 5 Get User Agent Information

Laravel 5 Get User Agent Information

By : Laravellogic Created : October 6, 2017 View : 1538

hello friend, in this tutorial i will be tell you how get user agent information (user agent mean user computer, mobile and browser details like ip-address browser languages etc) using laravel

User Agent is a PHP Computer/mobile user agent parser with support for Laravel 4 or 5 version, based on Mobile or Computer deveices. It provides both Computer support and additional functionality. This Laravel 4 and 5 package utilizes Mobile Detect PHP Class.

following below step you get User Agent informations.

Step 1:Installation

Open terminal after type the following command

composer require jenssegers/agent

Step 2:Laravel Setting

You go to this path config/app.php

Then add the service provider below line.


Then add the Agent alias below line.

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

Step 3: Basic Usage

Start by creating an Agent instance or use the Agent Facade

use Jenssegers\Agent\Agent;
$agent = new Agent();

create a new controller like AjentController and add below code

    		$data['robot'] = $agent->robot();

    	$data['regexp'] = $agent->match('regexp');
    	$data['languages'] = $agent->languages();

    	$data['browser'] = $agent->browser();
		$data['browser_version'] = $agent->version($data['browser']);

		$data['platform'] = $agent->platform();
		$data['platform_version'] = $agent->version($data['platform']);

		$data['device'] = $agent->device();

		// Check if the user is using a desktop device.
		if ($agent->isDesktop()) 
			$data['device_type'] = "Desktop";

		// Check if the user is using a phone device.
		if ($agent->isPhone()) 
			if($agent->isMobile()){$data['device_type'] = "Mobile";}
			if($agent->isTablet()){$data['device_type'] = "Tablet";}

			if($agent->isAndroidOS()){$data['device_os']= "Android";}
			if($agent->isNexus()){$data['device_os']= "Nexus";}
			if($agent->isSafari()){$data['device_os']= "Safari";}
			if($agent->is('iPhone')){$data['device_os']= "iPhone";}

		// get my real
    	$data['my_ip'] = $_SERVER['REMOTE_ADDR']; 

user ajent information in laravel

Basic Details

  • Check if the user is a robot or Not.
  • $agent->isRobot();


  • if the user is a robot then Get the robot name else false
  • $robot = $agent->robot();


  • Search the user agent with a regular expression
  • $agent->match('regexp');


  • Get the browser's accept languages. Like: ['nl-nl', 'nl', 'en-us', 'en']
  • $languages = $agent->languages();


  • Get the browser name. Like (Chrome, IE, Safari, Firefox, ...) and version Like (60.0.3112.10)
  • $browser = $agent->browser();
  • $version = $agent->version($browser);


To get the platform name and version you can use:

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


  • Get the device name, if mobile. Like (iPhone, Nexus, AsusTablet, ...)
  • $device = $agent->device();


  • Check if the user is using a desktop device or not.
  • $agent->isDesktop();


  • Check if the user is using a phone device or not.
  • $agent->isPhone()


  • Check for mobile device:
  • $agent->isMobile();
  • $agent->isTablet();


  • Magic method that does the same as the previous is() method:
  • $agent->isAndroidOS();
  • $agent->isNexus();
  • $agent->isSafari();


  • $agent->is('Windows');
  • $agent->is('Firefox');
  • $agent->is('iPhone');
  • $agent->is('OS X');