更改Laravel的默认登录方法? [英] Alter Laravel's default log in method?
本文介绍了更改Laravel的默认登录方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用php artisan make:auth
命令生成了身份验证控制器和路由.
每当用户登录时,我都希望在数据库中更新一个名为last_login
的字段.
解决方案
我已经更改了默认的Auth,以提供将用户密码从旧算法转换为bcrypt的功能(我正在重构旧版应用). /p>
我的操作方式:
app\Providers\EventServiceProvider.php
中:'Illuminate\Auth\Events\Login' => [
'App\Listeners\LogAuth',
],
i然后添加具有以下内容的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
}
}
我希望这会有所帮助.
I generated authentication controllers and routes using the php artisan make:auth
command.
I would like to update a field named last_login
in my database whenever a user logs in.
解决方案
I've altered the default Auth to provide the ability to convert users' passwords from an old algorithm to bcrypt (i'm refactoring a legacy app).
The way I did it:
in app\Providers\EventServiceProvider.php
:
'Illuminate\Auth\Events\Login' => [
'App\Listeners\LogAuth',
],
i then added the app\Listeners\LogAuth.php
file with the following contents
<?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
}
}
I hope this helps.
这篇关于更改Laravel的默认登录方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文