Laravel 5.2:用户登录后做某事? [英] Laravel 5.2 : Do something after user has logged in?

查看:191
本文介绍了Laravel 5.2:用户登录后做某事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我是Laravel的初学者)

我使用 Laravel 5.2 。我已成功启用验证;通过做 php artisan make:auth 和东西。

I'm using Laravel 5.2. I have successfully enabled the Authentication; by doing the php artisan make:auth and stuffs.

所以我的登录正在运行。

So my login is working.

现在,一旦有人登录,我需要做一些事情。一个简单的例子:

Now i need to do something once someone has logged in. For an simple example:

登录:


  • 一旦用户登录,在Session中写入一个值。

  • 例如: $ request-> session() - > put('UserAgent',$ ClientUserAgent);

  • Once a user has logged in, write a value into Session.
  • For example: $request->session()->put('UserAgent', $ClientUserAgent);

退出:


  • 一旦用户已经注销,删除自定义会话值就可以执行相同的操作。

  • 例如: $ request-> session() - > forget('UserAgent');

  • Same thing to do, once a user has logged out, delete the custom Session value.
  • For example: $request->session()->forget('UserAgent');

我不知道是否有(例如)钩子事件侦听器事件处理程序,或类似的东西。

I'm not sure whether there are (things like) hooks or Event Listeners, Event Handlers, or something like that.

我该怎么办?

How can i do it please?

推荐答案

小偷的回答< a>以下工作正常预期。但是,随着我googled,使用事件处理程序可能是更喜欢的方式。 (它的工作原理就像自定义钩子)。

Alief's Answer below works fine as expected. But as i googled through, using the Event Handlers is probably the more preferred way. (It works like custom hooks).

所以在下面的解释下面,请选择 - > 这个Event Handers方法我刚刚发现。

So without any less respects to Alief's Answer below, let me choose --> this Event Handers approach i just found out.

感谢所有关于!

这篇关于Laravel 5.2:用户登录后做某事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆