reefki/laravel-device-detector

Laravel wrapper for Matomo's Universal Device Detection library.

v1.0.0 2023-10-08 12:06 UTC

This package is auto-updated.

Last update: 2024-05-08 13:22:31 UTC


README

tests

The Laravel wrapper for Matomo Universal Device Detection library seamlessly integrates device detection capabilities into Laravel applications.

Installation

This package can be installed through Composer.

composer require reefki/laravel-device-detector

Optionally, you can publish the config file of this package with this command:

php artisan vendor:publish --provider="Reefki\DeviceDetector\DeviceDetectorServiceProvider" --tag="config"

Usage

Detect device from a user agent string:

use Reefki\DeviceDetector\Device;

$device = Device::detect($request->userAgent());

Detect device from a user agent string and optional hints:

use Reefki\DeviceDetector\Device;

$device = Device::detect($request->userAgent(), $request->server());

Detect device from a request instance:

use Reefki\DeviceDetector\Device;

$device = Device::detectRequest($request);

Detect device directly from a request instance:

$device = $request->device();

All of the above methods wil return a DeviceDetector\DeviceDetector instance which you can use to get the information about the device:

if ($device->isBot()) {
    $botInfo = $device->getBot();
} else {
    $clientInfo = $device->getClient();
    $osInfo = $device->getOs();
    $device = $device->getDeviceName();
    $brand = $device->getBrandName();
    $model = $device->getModel();
}

Read the Matomo's Universal Device Detection library readme for more information on how to use the returned instance.

Testing

Run the tests with:

vendor/bin/phpunit

Credits

License

The MIT License (MIT). Please see License File for more information.