Check Mobile Device or Desktop Laravel 5.8

Generic placeholder image
Brijpal Sharma
laravel  

Date:-August 08th, 2019 , Posted On:- Web Development


In this blog post, we learn how to check a mobile device or desktop Laravel 5.8. this post we will use a package "jenssegers/agent"

In many times need to need to detect devices using the application. we have a Jessenger agent package for the detection of mobile or desktop in Laravel 5.8. we can easily check which devices use users like mobile, tablet or desktop. this package has plugin provide a method to get all user device information the package "Jessenger" provide function like isMobile(), isTablet(), isDesktop() and device().

This package can easily use in all version of Laravel.you need to just follow bellow tutorial to detect mobile or desktop access device.

Step:1 Install package using composer 

To install package use this flowing command

composer require jenssegers/agent

After that, successfully install the package we need to set providers and alias.

Step:2 Set Providers

config/app.php


'providers' => [
	....
	Jenssegers\Agent\AgentServiceProvider::class,
]
'aliases' => [
	....
	'Agent' => Jenssegers\Agent\Facades\Agent::class,
]

 

Step:3 Create some route to return result

For Detect mobile device

Route::get('detect', function()
{
    $agent = new \Jenssegers\Agent\Agent;
   
    $mobileResult = $agent->isMobile();
    if($mobileResult){
      $result = $mobileResult;
    }
    $desktopResult= $agent->isDesktop();
    if($desktopResult){
      $result = $desktopResult;
    }
    $tabletResult= $agent->isTablet();
    if($tabletResult){
      $result = $tabletResult;
    }
    dd($result);
});

So we complated blog on check mobile device or desktop Laravel 5.8 


About the author

user profile
Brijpal Sharma

Hello, My Name is Brijpal Sharma. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of Codermen. I started this blog to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers...

0 comments

You must be logged in to post a comment.