Device Tracking in Laravel

News

October 27th, 2020

devices-featured.png

Laravel Device Tracking is a package by Ivano Matteo that allows you to track different devices used by users of your application. You can use this package as a base for functionality like detecting users on new devices and managing the verified status between device and user. You could also possibly see device hijacking.

The package works by adding the UseDevices trait to your application’s User model:

use IvanoMatteo\LaravelDeviceTracking\Traits\UseDevices;

class User extends Authenticatable
{

    use HasFactory, Notifiable, UseDevices;
    // ...
}

The UseDevices trait gives you access to a devices() (belongs to many) relationship to get verified devices:

$user->device()

Here are some examples of methods you can access via the package’s facade:

use IvanoMatteo\LaravelDeviceTracking\LaravelDeviceTrackingFacade as DeviceTracker;

DeviceTracker::detectFindAndUpdate();

DeviceTracker::flagCurrentAsVerified();

// Flag as verified for the current user
DeviceTracker::flagCurrentAsVerified();

// Flag as verified for a specific user
DeviceTracker::flagAsVerified($device, $user_id);

// Flag as verified for a specific user by device UUID
DeviceTracker::flagAsVerifiedByUuid($device_uuid, $user_id);

You can learn more about this package, get full installation instructions, and view the source code on GitHub at ivanomatteo/laravel-device-tracking.


This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.