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

注销:

  • 同样的事情,一旦用户退出,删除自定义 Session 值.
  • 例如:$request->session()->forget('UserAgent');

我不确定是否有(诸如)hooksEvent ListenersEvent Handlers 或类似的东西.

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

请问我该怎么做?

推荐答案

Alief's Answer 按预期工作正常.但正如我在谷歌上搜索的那样,使用 Event Handlers 可能是更受欢迎的方式.(它的工作方式类似于自定义挂钩).

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

因此,在不尊重下面 Alief 的回答的情况下,让我选择 --> 这个事件处理方法我刚刚发现.

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

谢谢大家的问候!

相关文章