anwarelbo / laravel-authentication-log
Laravel Authentication Log为Laravel提供认证日志和通知功能。
Requires
- php: >=7.0
- illuminate/auth: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/bus: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/console: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/contracts: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/database: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/http: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/notifications: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/support: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^3.5|^4.0|^5.0
- phpunit/phpunit: ^6.0|^7.0|^8.0
Suggests
- guzzlehttp/guzzle: Required to use the Slack transport (~6.0)
- nexmo/client: Required to use the Nexmo transport (~1.0).
README
安装
Laravel Authentication Log需要Laravel 5.5或更高版本,以及PHP 7.0+。
您可以使用Composer将Laravel Authentication Log安装到您的Laravel项目中
composer require yadahan/laravel-authentication-log
配置
安装Laravel Authentication Log后,使用vendor:publish
Artisan命令发布其配置、迁移和视图
php artisan vendor:publish --provider="Yadahan\AuthenticationLog\AuthenticationLogServiceProvider"
接下来,您需要迁移数据库。Laravel Authentication Log迁移将创建应用程序存储认证日志所需的表
php artisan migrate
最后,将AuthenticationLogable
和Notifiable
特质添加到您的认证模型(默认为App\User
模型)中。这些特质提供各种方法,让您获取常见的认证日志数据,例如最后登录时间、最后登录IP地址,并设置当从新设备登录时通知用户的消息渠道
use Illuminate\Notifications\Notifiable; use Yadahan\AuthenticationLog\AuthenticationLogable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable, AuthenticationLogable; }
基本用法
获取用户的全部认证日志
User::find(1)->authentications;
获取用户最后登录信息
User::find(1)->lastLoginAt(); User::find(1)->lastLoginIp();
获取用户上次登录时间及IP地址(忽略当前登录)
auth()->user()->previousLoginAt(); auth()->user()->previousLoginIp();
通知新设备登录
通知可以通过mail
、nexmo
和slack
渠道发送。默认通过电子邮件发送。
您可以通过定义notifyAuthenticationLogVia
方法来确定通知应该通过哪些渠道发送
/** * The Authentication Log notifications delivery channels. * * @return array */ public function notifyAuthenticationLogVia() { return ['nexmo', 'mail', 'slack']; }
当然,您可以通过在config/authentication-log.php
配置文件中将notify
选项设置为false
来禁用通知
'notify' => env('AUTHENTICATION_LOG_NOTIFY', false),
清除旧日志
您可以使用authentication-log:clear
Artisan命令清除旧的认证日志记录
php artisan authentication-log:clear
将删除比您在config/authentication-log.php
中的older
选项中指定的天数更早的记录
'older' => 365,
贡献
感谢您考虑为Laravel Authentication Log做出贡献。
许可证
Laravel Authentication Log是开源软件,采用MIT许可证。