Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Devices Laravel Package

diego-ninja/laravel-devices

Laravel package for tracking authenticated user devices and managing sessions. Includes device verification, fingerprinting integrations, session locking/blocking with optional Google 2FA, location tracking, events, middleware/controllers, and caching support.

View on GitHub
Deep Wiki
Context7

🚀 Quickstart

Service provider

Add the service provider to bootstrap/providers.php under providers:

return [ 
	...        
	Ninja\DeviceTracker\DeviceTrackerServiceProvider::class,    
]  

Config file

Update config file to fit your needs:

config/devices.php  

Run migrations

Migrate your database to create the necessary tables:

php artisan migrate  

Configure model

Add the HasDevices trait to your user model:

use Ninja\DeviceTracker\Traits\HasDevices;        

class User extends Model {  
	use HasDevices;    
	...
}  

Add the Has2FA trait to your user model if you want to use the Google 2FA provided integration:

use Ninja\DeviceTracker\Traits\Has2FA;        

class User extends Model {  
	use Has2FA;    
	...
}  

Add middlewares:

Add the DeviceTrack middleware in your bootstrap/app.php file. This middleware will track the user device, it will check the presence of a cookie with a device uuid and will create a new device if it doesn't exist.

Optionally, you can add the FingerprintTracker middleware to try to fingerprint the device. This middleware uses javascript injection to work, so, it only works on html responses. Thi middleware needs a current device to work, so it should be placed after the DeviceTracker middleware.

protected $middleware = [
	'Ninja\DeviceTracker\Http\Middleware\DeviceTracker',
	...
	'Ninja\DeviceTracker\Modules\Fingerprinting\Http\Middleware\FingerprintTracker',
];

In your routes.php file you should add 'session-tracker' middleware for routes which you want to keep track of. This middleware will check if the user has a valid session and device. If not, it will redirect to the login page or return a 401 json response depending on your configuration.

Route::group(['middleware'=>'session-tracker'], function(){
    Route::get('your-route', 'YourController@yourAction');    
});

Next Steps

Once installed, you should:

  1. Review the Configuration Guide for detailed setup options
  2. Set up Device Fingerprinting if needed
  3. Configure Two-Factor Authentication if required

For more information on specific features:

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport