Listeners 监听用户登录 偶偶不起作用
第一次登录不会触发,长时间后重新登录也不会触发
只有登录后退出 又马上登录才会触发 是什么情况?
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
'Illuminate\Auth\Events\Login' => [
'App\Listeners\LogSuccessfulLogin',
],
];
<?php
namespace App\Listeners;
use Illuminate\Auth\Events\Login;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Jenssegers\Agent\Agent;
class LogSuccessfulLogin
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param Login $event
* @return void
* login => 1, registered => 2
*/
public function handle(Login $event)
{
$agent = new Agent();
DB::table('user_login_log')->insert([
'user_id' => $event->user->id,
'username' => $event->user->name,
'login_ip' => $_SERVER["HTTP_CF_CONNECTING_IP"],
'login_city' => $_SERVER["HTTP_CF_IPCOUNTRY"],
'login_time' => $event->user->updated_at,
'device' => $agent->device(),
'type' => '1',
'browser' => $agent->browser().$agent->version($agent->browser()),
]);
}
}
推荐文章: