定制 makkinga/laravel-trusted-devices 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固