Desktop/mobile user agent parser with support for Laravel, based on MobileDetect
spinzar/laravel-agent is a Laravel package for desktop/mobile user agent parser with support for laravel, based on mobiledetect.
It currently has 0 GitHub stars and 0 downloads on Packagist.
Install it with composer require spinzar/laravel-agent.
Discover more Laravel packages by spinzar
or browse all Laravel packages to compare alternatives.
Last updated
Install using composer:
composer require spinzar/laravel-agent
Add the service provider in config/app.php:
Spinzar\LaravelAgent\AgentServiceProvider::class,
And add the LaravelAgent alias to config/app.php:
'LaravelAgent' => Spinzar\LaravelAgent\Facades\LaravelAgent::class,
Start by creating an LaravelAgent instance (or use the LaravelAgent Facade if you are using Laravel):
use Spinzar\LaravelAgent\LaravelAgent;
$larvaelagent = new LaravelAgent();
If you want to parse user agents other than the current request in CLI scripts for example, you can use the setUserAgent and setHttpHeaders methods:
$larvaelagent->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2');
$larvaelagent->setHttpHeaders($headers);
Check for a certain property in the user agent.
$larvaelagent->is('Windows');
$larvaelagent->is('Firefox');
$larvaelagent->is('iPhone');
$larvaelagent->is('iPad');
$larvaelagent->is('OS X');
Magic method that does the same as the previous is() method:
$larvaelagent->isAndroidOS();
$larvaelagent->isNexus();
$larvaelagent->isSafari();
Check for mobile device:
$larvaelagent->isMobile();
$larvaelagent->isTablet();
Search the user agent with a regular expression:
$larvaelagent->match('regexp');
Get the browser's accept languages. Example:
$languages = $larvaelagent->languages();
// ['nl-nl', 'nl', 'en-us', 'en']
Get the device name, if mobile. (iPhone, Nexus, AsusTablet, ...)
$device = $larvaelagent->device();
Get the operating system. (Ubuntu, Windows, OS X, ...)
$platform = $larvaelagent->platform();
Get the browser name. (Chrome, IE, Safari, Firefox, ...)
$browser = $larvaelagent->browser();
Check if the user is using a desktop device.
$larvaelagent->isDesktop();
This checks if a user is not a mobile device, tablet or robot.
Check if the user is using a phone device.
$larvaelagent->isPhone();
Check if the user is a robot. This uses jaybizzle/crawler-detect to do the actual robot detection.
$larvaelagent->isRobot();
Get the robot name.
$robot = $larvaelagent->robot();
MobileDetect recently added a version method that can get the version number for components. To get the browser or platform version you can use:
$browser = $larvaelagent->browser();
$version = $larvaelagent->version($browser);
$platform = $larvaelagent->platform();
$version = $larvaelagent->version($platform);
Note, the version method is still in beta, so it might not return the correct result.
Laravel User Agent is licensed under The MIT License (MIT).