首页 文章

Laravel 5.0扩展了'Logout'功能

提问于
浏览
3

我最近设置了会话以保存到数据库并在sessions表中添加了user_id字段,以便我可以显示登录用户的名称 . 为了让laravel在用户登录时保存用户的id(给定laravel不定期查找user_id列),我不得不在Authenticate.php文件中添加一些代码来处理它 .

现在,我试图在用户注销时将user_id字段设置为 null 因为目前,因为user_id字段即使在他们注销后仍然包含用户的id,即使他们不再登录,它仍会显示为已登录我希望扩展auth / logout功能而不实际触及供应商文件以包含我的功能,以便在注销时将user_id设置为null .

我可以在哪里添加此功能?在AuthController.php文件中?在routes.php中添加我自己的auth / logout路由声明?

如果您对我有任何疑问或需要我更好地解释一下,请告诉我 .

谢谢 .

1 回答

  • 6

    您可以在 AuthController.php 中添加以下功能以覆盖 AuthenticatesAndRegistersUsers trait中的默认功能 . 您可以根据需要进行更改 .

    /**
         * Log the user out of the application.
         *
         * @return \Illuminate\Http\Response
         */
        public function getLogout()
        {
            $this->auth->logout();
    
            return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
        }
    

相关问题