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

Laravel 5 中的登錄事件處理

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

問(wèn)題描述

即使在我的 L5 應(yīng)用程序中,我也試圖登錄以設(shè)置上次登錄時(shí)間和 IP 地址.我可以通過(guò)以下方式使其工作:

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 中使用事件處理程序?qū)ο蟮淖罴逊椒ㄊ鞘裁?我嘗試創(chuàng)建一個(gè)事件處理程序并將 auth.login 添加為事件服務(wù)提供程序中的數(shù)組鍵,但是這不起作用.我不確定 auth.login 事件是否可行.如果不是,上面代碼放在哪里最合適.為了測(cè)試,我把它放在了我的 routes.php 文件中,但我知道那不是它應(yīng)該在的地方.

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.*.

有關(guān) 5.2.* 解決方案,請(qǐng)參閱下面的 JuLiAnc 回復(fù).

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

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.

我運(yùn)行了以下工匠命令

$ php artisan handler:event AuthLoginEventHandler

然后我更改了生成的類(lèi),刪除了 Event 類(lèi)的導(dǎo)入,并導(dǎo)入了用戶(hù)模型.我還將 User $user$remember 傳遞給 handle 方法,因?yàn)楫?dāng) auth.login 事件被觸發(fā)時(shí),這就是傳遞的內(nèi)容.

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");
    }

}

現(xiàn)在我打開(kāi)了 EventServiceProvided.php 并修改了 $listen 數(shù)組如下:

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

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

我意識(shí)到如果一開(kāi)始這不起作用,您可能需要

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

$ php artisan clear-compiled

我們走了!我們現(xiàn)在可以使用事件處理程序類(lèi)通過(guò) auth.login 事件響應(yīng)用戶(hù)登錄!

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

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

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

相關(guān)文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢(xún))
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數(shù))
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數(shù)中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應(yīng)內(nèi)容必須是實(shí)現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動(dòng)到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪(fǎng)問(wèn)某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 在线观看日韩av | 国产蜜臀av | 一级大毛片 | 成人免费激情视频 | 亚洲一区视频在线 | 日韩国产一区二区 | 黄色一级视频在线观看 | 中文字幕+乱码+中文乱码91 | 日韩一区二区三区av | 日韩欧美一区二区三区久久婷婷 | 91在线一区二区 | 欧美日韩中文在线 | 伊人久久免费视频 | 麻豆一区二区三区 | 蜜臀久久99精品久久久久宅男 | 免费看黄色录像 | 五月天一区二区 | 久久精品视频免费 | 成人免费看片98欧美 | 中文字幕一区在线观看 | 国产精品久久久久久久成人午夜 | 国产精品成人一区二区三区 | 一级黄色网 | 亚洲激情网 | 国产伦精品一区二区三区视频黑人 | 日韩视频免费在线观看 | 欧美精品在线免费观看 | 成人羞羞国产免费 | 免费av播放 | 999久久久久久久久6666 | 日本中文字幕一区 | a级黄毛片 | 欧美国产日韩一区二区 | 中文字字幕 | 色哟哟一区二区 | 国产欧美久久久 | 国产在线天堂 | 国产精品一区在线播放 | 中文字幕观看 | 免费理论片 | 日韩在线视频一区 |