【问题标题】:Laravel how to call protected function fireOtherDeviceLogoutEvent() from UserController?Laravel如何从UserController调用受保护的函数fireOtherDeviceLogoutEvent()?
【发布时间】:2021-08-18 13:34:54
【问题描述】:

在 Illuminate/Auth/SessionGuard.php 中有一个方法fireOtherDeviceLogoutEvent($user)

我想从我的 UserController 中调用它。

最好的方法是什么?

【问题讨论】:

    标签: laravel laravel-6


    【解决方案1】:

    我认为你可以编写一个新函数并在控制器中调用它。

    希望对你有帮助。

    use Illuminate\Auth\Events\OtherDeviceLogout;
    protected function fireOtherDeviceLogoutEvent()
    {
        $name = Auth::getName();
        $user = Auth::user();
        event(new OtherDeviceLogout($name, $user));
    }
    

    【讨论】:

    • 我无法使用 logoutOtherDevices(),因为我们在本地数据库中没有用户表,而是使用外部 API 来处理用户。据我了解,logoutOtherDevices 更改了用户表中的密码哈希,而我们的外部 api 不支持这一点。
    • @EmilyTuiCh 我已经编辑了答案,你可以再参考一下。
    猜你喜欢
    • 2017-12-12
    • 2014-11-03
    • 2015-08-26
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 2012-08-28
    • 2021-10-05
    • 2011-05-20
    相关资源
    最近更新 更多