Add the service provider to bootstrap/providers.php
under providers
:
return [
...
Ninja\DeviceTracker\DeviceTrackerServiceProvider::class,
]
Update config file to fit your needs:
config/devices.php
Migrate your database to create the necessary tables:
php artisan migrate
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 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');
});
Once installed, you should:
- Review the Configuration Guide for detailed setup options
- Set up Device Fingerprinting if needed
- Configure Two-Factor Authentication if required
For more information on specific features: