A user agent class for Laravel, based on Mobile Detect with extended functionality.
The previous version is still available under the 1.0.0 tag.
Install using composer:
composer require jenssegers/agent
Add the service provider in app/config/app.php
:
'Jenssegers\Agent\AgentServiceProvider',
And add the Agent alias to app/config/app.php
:
'Agent' => 'Jenssegers\Agent\Facades\Agent',
All of the original Mobile Detect functionality is still available, check out more examples over at https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples
Check for a certain property in the user agent.
Agent::is('Windows');
Agent::is('Firefox');
Agent::is('iPhone');
Agent::is('OS X');
Magic method that does the same as the previous is()
method:
Agent::isAndroidOS();
Agent::isNexus();
Agent::isSafari();
Check for mobile device:
Agent::isMobile();
Agent::isTablet();
Search the user agent with a regular expression:
Agent::match('regexp');
Since the original library was inspired on CodeIgniter, I decided to add some additional functionality:
Get the browser's accept languages. Example:
$languages = Agent::languages();
// ['nl-nl', 'nl', 'en-us', 'en']
Get the device name, if mobile. (iPhone, Nexus, AsusTablet, ...)
Agent::device();
Get the operating system. (Ubuntu, Windows, OS X, ...)
Agent::platform();
Get the browser name. (Chrome, IE, Safari, Firefox, ...)
Agent::browser();
Check if the user is a desktop.
Agent::isDesktop();
This checks if a user is not a mobile device, tablet or robot.
Check if the user is a robot.
Agent::isRobot();
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 = Agent::browser();
$version = Agent::version($browser);
$platform = Agent::platform();
$version = Agent::version($platform);
Note, the version method is still in beta, so it might not return the correct result.