我使用 php artisan make:auth
命令生成了身份验证控制器和路由。
我想在用户登录时更新数据库中名为 last_login
的字段。
我已经更改了默认身份验证,以提供将用户密码从旧算法转换为 bcrypt 的功能(我正在重构旧版应用程序)。
我这样做的方式:
在app'Providers'EventServiceProvider.php
:
'Illuminate'Auth'Events'Login' => [
'App'Listeners'LogAuth',
],
然后,我添加了包含以下内容的app'Listeners'LogAuth.php
文件
<?php
namespace App'Listeners;
use Illuminate'Auth'Events'Attempting;
use Illuminate'Queue'InteractsWithQueue;
use Illuminate'Contracts'Queue'ShouldQueue;
use Auth, App'User, Hash;
class LogAuth {
public function __construct()
{
//
}
public function handle($credentials, $remember, $login)
{
// get the user, update the column, save
}
}
我希望这有所帮助。