久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel 5 中的登錄事件處理

login event handling in laravel 5(Laravel 5 中的登錄事件處理)
本文介紹了Laravel 5 中的登錄事件處理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

即使在我的 L5 應用程序中,我也試圖登錄以設置上次登錄時間和 IP 地址.我可以通過以下方式使其工作:

i am trying to hook to the login even in my L5 app to set last login time and IP address. i can make it work with the following:

Event::listen('auth.login', function($event)
{
    Auth::user()->last_login = new DateTime;
    Auth::user()->last_login_ip = Request::getClientIp();
    Auth::user()->save();
});

但是,我想知道在 L5 中使用事件處理程序對象的最佳方法是什么.我嘗試創建一個事件處理程序并將 auth.login 添加為事件服務提供程序中的數組鍵,但是這不起作用.我不確定 auth.login 事件是否可行.如果不是,上面代碼放在哪里最合適.為了測試,我把它放在了我的 routes.php 文件中,但我知道那不是它應該在的地方.

however, i am wondering what the best way to do this in L5 is with the event handler object. i tried creating an event handler and adding auth.login as an array key in the events service provider, however that didnt work. im not sure if that is possible or not with the auth.login event. if it isnt, where is the most appropriate place to put the above code. for testing, i put it in my routes.php file, but i know that isnt where it should be.

推薦答案

這只適用于 5.0.* 和 5.1.*.

有關 5.2.* 解決方案,請參閱下面的 JuLiAnc 回復.

在處理了兩個建議的答案并進行了更多研究之后,我終于想出了如何按照我最初嘗試的方式做到這一點.

after working with both proposed answers, and some more research i finally figured out how to do this the way i was trying at first.

我運行了以下工匠命令

$ php artisan handler:event AuthLoginEventHandler

然后我更改了生成的類,刪除了 Event 類的導入,并導入了用戶模型.我還將 User $user$remember 傳遞給 handle 方法,因為當 auth.login 事件被觸發時,這就是傳遞的內容.

Then i altered the generated class removing the import of the Event class and and imported the user model. I also passed User $user and $remember to the handle method since when the auth.login event is fired, thats what is passed.

<?php namespace AppHandlersEvents;

use IlluminateQueueInteractsWithQueue;
use IlluminateContractsQueueShouldBeQueued;
use AppUser;

class AuthLoginEventHandler {

    /**
     * Create the event handler.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  User $user
     * @param  $remember
     * @return void
     */
    public function handle(User $user, $remember)
    {
        dd("login fired and handled by class with User instance and remember variable");
    }

}

現在我打開了 EventServiceProvided.php 并修改了 $listen 數組如下:

now i opened EventServiceProvided.php and modified the $listen array as follows:

protected $listen = [
    'auth.login' => [
        'AppHandlersEventsAuthLoginEventHandler',
    ],
];

我意識到如果一開始這不起作用,您可能需要

i realized if this doesn't work at first, you may need to

$ php artisan clear-compiled

我們走了!我們現在可以使用事件處理程序類通過 auth.login 事件響應用戶登錄!

There we go! we can now respond to the user logging in via the auth.login event using an event handler class!

這篇關于Laravel 5 中的登錄事件處理的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 日韩精品一区二区在线观看 | 国产视频一区二区在线观看 | 国产精品久久久久久久久久不蜜臀 | 日韩在线小视频 | 欧美日韩在线免费 | 亚洲网站在线观看 | 精品国产乱码久久久久久a丨 | 精品欧美一区二区三区精品久久 | 亚洲欧美一区二区三区国产精品 | 天天干天天谢 | 动漫www.被爆羞羞av44 | 欧美精品欧美精品系列 | 日韩在线一区二区 | 成人在线视频一区 | 日韩精品欧美精品 | 国产欧美一区二区久久性色99 | 五月花丁香婷婷 | 99国产精品一区二区三区 | 91视频一区二区 | 国产精品久久久久一区二区三区 | 欧美激情综合色综合啪啪五月 | 国产一区二区三区视频免费观看 | 中文字幕乱码视频32 | av免费看片| 欧美日本韩国一区二区 | 成人美女免费网站视频 | 日韩中文字幕视频 | 亚洲国产精品久久久 | 日本欧美视频 | 一级毛片成人免费看a | 91久久精品国产91久久 | 久在线 | 国产在线精品一区二区三区 | 成人在线观看中文字幕 | 日本小视频网站 | 久久精品中文 | 亚洲免费影院 | 蜜桃视频在线观看免费视频网站www | 国产成人精品久久二区二区91 | 国产成人精品一区二区三区在线 | 黄色毛片视频 |