Device Detector is a convenient package for applications, offering easy detection of user devices and their operating systems. Utilizing the mobiledetect/mobiledetectlib
library, this package enables applications to quickly identify device types (mobile, tablet, desktop) and operating systems (iOS, Android, etc.), enhancing the user experience and providing valuable insights.
- Detect whether the user's device is a mobile, tablet, or desktop
- Identify the operating system of the user's device (iOS, Android, etc.)
- Lightweight and easy to integrate into any project
Install the package via composer:
composer require kwenziwa/devicedetector
After installation, you can use the DeviceDetector in your application as follows:
use Kwenziwa\DeviceDetector\DeviceDetector;
$deviceDetector = app(DeviceDetector::class);
if ($deviceDetector->isMobile()) {
// Handle mobile device
}
if ($deviceDetector->isTablet()) {
// Handle tablet device
}
if ($deviceDetector->isDesktop()) {
// Handle desktop device
}
Determines if the user's device is a mobile phone.
$deviceDetector->isMobile();
Determines if the user's device is a tablet.
$deviceDetector->isTablet();
Determines if the user's device is a desktop. This is typically the default if the device is neither a mobile nor a tablet.
$deviceDetector->isDesktop();
Checks if the user's device is running iOS.
$deviceDetector->isIOS();
Checks if the user's device is running Android OS.
$deviceDetector->isAndroidOS();
Returns the type of the user's device as a string ('mobile', 'tablet', or 'desktop').
$deviceType = $deviceDetector->getDeviceType();
Returns the operating system of the user's device as a string (e.g., 'iOS', 'Android', 'Windows Mobile', 'BlackBerry', 'Symbian', or 'Unknown').
$osType = $deviceDetector->getOSType();
Returns the the browser name system of the user's device as a string.
$detector = new DeviceDetector();
$browser = $detector->getBrowser();
echo "Browser: $browser";
Run the tests using the PHPUnit command:
./vendor/bin/phpunit
This command will execute all tests in your tests directory. The above tests are basic and might not effectively cover all scenarios since the actual device type and OS will depend on the environment where the tests are run. In a more comprehensive test suite, you would mock the MobileDetect class to simulate different devices and operating systems. This would allow you to test all branches of your code.
Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github.
The Device Detector is open-sourced software licensed under the MIT license.