久久久久久久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ⅴ毛片 | 99久久亚洲 | 亚洲精品在线视频 | 国产精品高潮呻吟久久 | 日韩中文字幕 | 久久美女视频 | 精品免费国产一区二区三区四区介绍 | 日韩电影中文字幕 | 日韩av成人在线 | 欧美日韩精品免费观看 | 国产jizz女人多喷水99 | 精品一区二区免费视频 | 羞羞视频网站免费看 | 亚洲日本乱码在线观看 | 男女网站免费观看 | 日韩美香港a一级毛片免费 国产综合av | 日韩在线免费视频 | 一区二区三区欧美在线 | 91网站在线播放 | 免费黄色大片 | 在线国产一区二区 | 久久精品| 在线观看国产视频 | 亚洲天堂久久 | 久久综合888 | 在线观看视频福利 | 日本精品一区二区三区在线观看视频 | 亚洲成人精品一区 | 日韩影院在线观看 | 99久久久久久 | 请别相信他免费喜剧电影在线观看 | 亚洲欧美另类在线 | 久久高清国产 | 国产精品电影在线观看 | 欧美一区二区另类 | 综合五月婷| 伊人伊人 | 鸳鸯谱在线观看高清 |