How to detect devices is mobile or desktop in Laravel?

How to detect devices is mobile or desktop in Laravel?

In this post we will give you information about How to detect devices is mobile or desktop in Laravel?. Hear we will give you detail about How to detect devices is mobile or desktop in Laravel?And how to use it also give you demo for it if it is necessary.

Few days ago i need to detect devices access from mobile, desktop or tablet in laravel 5 app. i find out jessenger agent package for detection of mobile or desktop in laravel 5.8. we can easily check which devices use user like mobile, tablet or desktop.

jessenger ajent plugin provide method to get all user agent values with their pre define function by package. they provide function like isMobile(), isTablet(), isDesktop() and device(). there are more helper provide for user agent. we can easily use with laravel 5.1, laravel 5.2, laravel 5.3, laravel 5.4, laravel 5.5, laravel 5.6, laravel 5.7 etc.

You have to just follow bellow tutorial to detect mobile or desktop access device.

Install jessenger/ajent Package

We need to install jessenger/ajent composer package for getting user ajent value, so you can install using following command:

composer require jenssegers/agent

After that you need to set providers and alias.

config/app.php

.....

'providers' => [

....

JenssegersAgentAgentServiceProvider::class,

]

'aliases' => [

....

'Agent' => JenssegersAgentFacadesAgent::class,

]

.....

Now bellow i will create route and you can see how to use it.

Detect Is Mobile:

Route::get('detect', function()

{

$agent = new JenssegersAgentAgent;

$result = $agent->isMobile();

dd($result);

});

Detect Is Desktop:

Route::get('detect', function()

{

$agent = new JenssegersAgentAgent;

$result = $agent->isDesktop();

dd($result);

});

Detect Is Tablet:

Route::get('detect', function()

{

$agent = new JenssegersAgentAgent;

$result = $agent->isTablet();

dd($result);

});

You can also make condition in view blade file like as bellow:

Also see:Laravel 5.8 Datatables Tutorial

@if((new JenssegersAgentAgent())->isDesktop())

<link rel="stylesheet" href="http://tridentsportscars.com/?big={{ asset("front/css/desktop.css') }}" />

@endif

@if((new JenssegersAgentAgent())->isMobile())

<link rel="stylesheet" href="http://tridentsportscars.com/?big={{ asset("front/css/mobile.css') }}" />

@endif

I hope you found your best tutorial…

Hope this code and post will helped you for implement How to detect devices is mobile or desktop in Laravel?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  79  =  82

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US