karmendra / laravel-agent-detector
Laravel wrapper for matomo-org/device-detector user agent parser
Installs: 15 796
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 3
Open Issues: 1
Requires
- matomo/device-detector: ^4.3
Suggests
- illuminate/support: Required for laravel service providers
This package is not auto-updated.
Last update: 2024-11-08 05:11:23 UTC
README
A PHP desktop/mobile user agent parser for Laravel, based on Device Detector that will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Goto http://devicedetector.net for a quick demo of what this library can detect.
Installation
Install using composer:
composer require karmendra/laravel-agent-detector
Laravel (optional)
Add the service provider in config/app.php
:
Karmendra\LaravelAgentDetector\AgentDetectorServiceProvider::class,
And add the AgentDetector alias to config/app.php
:
'AgentDetector' => Karmendra\LaravelAgentDetector\Facades\AgentDetector::class,
Basic Usage
Start by creating an AgentDetector
instance (or use the AgentDetector
Facade):
use Karmendra\LaravelAgentDetector\AgentDetector; $user_agent = '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'; $ad = new AgentDetector($user_agent);
If you want set different user agents on the fly in CLI scripts for example, you can use the setUserAgent
$ad->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');
All of the original Device Detector methods are still available
Additional Functionality
Device type
Get the device type. (smartphone
, mobile
, tablet
, desktop
, bot
...)
$type = $ad->device();
Device brand name
Get the device manufactures brand name, if mobile. (Apple
, Nexus
, Samsung
, ...)
$brand = $ad->deviceBrand();
Device model
Get the device model, if mobile. (Apple: iPhone
, Samsung: Galaxy S9
...)
$model = $ad->deviceModel();
Platform / Operating system name
Get the operating system. (Ubuntu
, Android
, Windows
, Mac
, iOS
, ...)
$platform = $ad->platform();
Platform version (OS version).
Get the platform version. (Windows: 10
, Mac: 10.11
, Android: 9.0
, ...)
$platform_version = $ad->platformVersion();
Browser name
Get the browser name. (Chrome
, IE
, Safari
, UC Browser
, ...)
$browser = $ad->browser();
Browser version
Get the browser name. (Chrome: 56
, Safari: 9.0
, Firefox: 48
, ...)
$browser_version = $ad->browserVersion();
Robot detection
Check if the user is a robot. (true
or false
)
$ad->isBot();
To-do (PR welcome):
- Adding test cases
- Adding additional functions for getting robot info, enable disable robot detection etc.
License
Laravel Agent Detector is licensed under The MIT License (MIT).