makkinga/laravel-trusted-devices
最新稳定版本:1.3.2
Composer 安装命令:
composer require makkinga/laravel-trusted-devices
包简介
Add trusted devices to your user models
README 文档
README
Installation
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"
IpInfo
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}"
Usage
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');
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-25
