Alter Laravel's default log in method?

懵懂的女人 提交于 2019-12-13 05:48:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/34880747/alter-laravels-default-log-in-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!