Add trusted devices to your user models
makkinga/laravel-trusted-devices is a Laravel package for add trusted devices to your user models.
It currently has 4 GitHub stars and 29 downloads on Packagist (latest version 1.3.2).
Install it with composer require makkinga/laravel-trusted-devices.
Discover more Laravel packages by makkinga
or browse all Laravel packages to compare alternatives.
Last updated

You can install the package via composer:
composer require makkinga/laravel-trusted-devices
You can publish and run the migrations with:
php artisan vendor:publish --tag="trusted-devices-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="trusted-devices-config"
This is the contents of the published config file:
return [
# Overwrite the auto detection of the guard
'guard' => null,
# The layout to use for the views
'layout' => 'layouts.app',
# The middleware to use for the routes
'middleware' => ['web', 'auth'],
# Automatically trust the first device
'trust_first_device' => true
];
Optionally, you can publish the views using
php artisan vendor:publish --tag="trusted-devices-views"
In order to make use of IpInfo.io's free 50k requests per month rate limit, add your API token to your .env:
TRUSTED_DEVICES_IPINFO_TOKEN="{your_token}"
Prepare your user model by adding the HasTrustedDevices trait and also make sure it is using the Notifiable trait:
use Illuminate\Notifications\Notifiable;
use Makkinga\TrustedDevices\Traits\HasTrustedDevices;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable, HasTrustedDevices;
}
Then add the trusted device middleware to your $routeMiddleware in app/Http/Kernel.php:
use Makkinga\TrustedDevices\Middleware\EnsureDeviceIsTrusted;
protected $routeMiddleware = [
[...]
'trusted' => EnsureDeviceIsTrusted::class,
];
You can now use the "trusted" middleware on your routes and route groups like this:
Route::middleware(['auth', 'trusted'])->group(function () {
// Your routes
});
Route::get('/my-route', [MyController::class, 'method'])->name('my-route')->middleware('trusted');
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.