How To Detect Device is Mobile or Desktop in Laravel 8

Reading Time: 4 minutes

Inside this article we will see the concept of device detection composer package inside laravel application. How to detect device is mobile or desktop in Laravel 8, we will discuss in this article.

Always developer or designer wants to know that whenever they open application which device is being to used for it. So for this we will use jessenger agent package for device detection.

Device detection in application is process in which you will the device information, browser information etc where your application runs.

Learn More –

Let’s get started.

Laravel Installation

We will create laravel project using composer. So, please make sure your system should have composer installed. If not, may be this article will help you to Install composer in system.

Here is the command to create a laravel project-

composer create-project --prefer-dist laravel/laravel blog

To start the development server of Laravel –

php artisan serve


Assuming laravel already installed inside your system.

Install jessenger/ajent Package

Open project into terminal and run this command to install this device detection package.

$ composer require jenssegers/agent

It will install jessenger/ajent package inside application.

Provider & Alias Settings

Open app.php from /config folder.

Search for providers & aliases and these lines into it.


'providers' => [



'aliases' => [

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



Usage of Detection Package

Before use of jenssegers/agent package, we need to create an instance. By using that instance we can call device detection methods.

Object/Instance Creation

$agent = new \Jenssegers\Agent\Agent;

Detect Mobile


Detect Laptop/Desktop


Detect Tablet


All these methods returns boolean value.

Here, we have a sample code for application to check device.


Route::get('detect-device', function () {

    // object
    $agent = new \Jenssegers\Agent\Agent;

    // laptop/desktop
    $result1 = $agent->isDesktop();

    // mobile
    $result2 = $agent->isMobile();

    // tablet
    $result3 = $agent->isTablet();

    // returns boolean value of each variable
    echo $result1." , ".$result2. " , ".$result3; 


How to Use Agent Methods in Blade Layouts

Also we have an option available when we need to use $agent methods in blade layouts directly.

@if((new \Jenssegers\Agent\Agent())->isDesktop())
      DO STUFF

@if((new \Jenssegers\Agent\Agent())->isMobile())
      DO STUFF

@if((new \Jenssegers\Agent\Agent())->isTablet())
      DO STUFF

More Useful Notes About Package

We have lots of methods available by this Agent facade. Using these methods you can know platform, browser, browser version, etc.

// Ubuntu, Windows, OS X, ...

// Chrome, IE, Safari, Firefox, ...

$browser = $agent->browser();

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

$platform = $agent->platform();

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




$agent->is('OS X');




// ['nl-nl', 'nl', 'en-us', 'en']

// iPhone, Nexus, AsusTablet, ...






// robot name

We hope this article helped you to learn How To Detect Device is mobile or desktop in Laravel 8 Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more