How To Detect Device is Mobile or Desktop in Laravel 8

Installation of Laravel Application

  • Laravel Installer
  • By using composer

Laravel Installer

$composer global require laravel/installer
$laravel new blog

By using composer

$composer create-project --prefer-dist laravel/laravel blog
$php artisan serve

Install jessenger/ajent Package

$ composer require jenssegers/agent

Provider & Alias Settings

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

Usage of Detection Package

$agent =new \Jenssegers\Agent\Agent;
$agent->isMobile();
$agent->isDesktop();
$agent->isTablet();
//... 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

#Desktop/Laptop @if((new \Jenssegers\Agent\Agent())->isDesktop()) DO STUFF @endif#Mobile @if((new \Jenssegers\Agent\Agent())->isMobile()) DO STUFF @endif#Tablet @if((new \Jenssegers\Agent\Agent())->isTablet()) DO STUFF @endif

More Useful Notes About Package

$agent->platform(); // Ubuntu, Windows, OS X, ... $agent->browser(); // Chrome, IE, Safari, Firefox, ... $browser = $agent->browser(); $version = $agent->version($browser); $platform = $agent->platform(); $version = $agent->version($platform); $agent->is('Windows'); $agent->is('Firefox'); $agent->is('iPhone'); $agent->is('OS X'); $agent->isAndroidOS(); $agent->isNexus(); $agent->isSafari(); $agent->languages(); // ['nl-nl', 'nl', 'en-us', 'en'] $agent->device(); // iPhone, Nexus, AsusTablet, ... $agent->isDesktop(); $agent->isPhone(); $agent->isMobile(); $agent->isTablet(); $agent->isRobot(); $agent->robot(); // robot name

Find More on Laravel 8 Articles here

--

--

--

Online Web Tutor is web development community found by Sanjay Kumar. It provides web development course for free worldwide by professionally trained instructors

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Testing From Trenches, An Unexpected Use Case For Strava — Tentamen Software Testing Blog

Roles In Software Development Project — Tentamen Software Testing Blog

Tips to write a good bug report

Meet Lakshyana K.C. from Build Change, bringing new skills to solve societal problems

API for QA: Testing features when you have no access to code

How I start @TwitterDev Community in Bangladesh

MLH FELLOWSHIP WITH AMAZON AWS AMPLIFY

What Are Interfaces?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Online Web Tutor

Online Web Tutor

Online Web Tutor is web development community found by Sanjay Kumar. It provides web development course for free worldwide by professionally trained instructors

More from Medium

How To Get Month Name from Date in PHP Tutorial

Build Web App Mini Sosmed with Laravel 8 [Part 3]

Laravel Advance | Laravel Broadcast Redis Socket io Tutorial

Accessor and Mutator In Laravel 8