Device Tracking in Laravel
Published on by Paul Redmond
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 userDeviceTracker::flagCurrentAsVerified(); // Flag as verified for a specific userDeviceTracker::flagAsVerified($device, $user_id); // Flag as verified for a specific user by device UUIDDeviceTracker::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