【问题标题】:Logging out with Laravel 5.1使用 Laravel 5.1 注销
【发布时间】:2016-02-13 00:03:09
【问题描述】:

我已经使用 Laravel 5.1 3 天了,今天我遇到了障碍。我正在尝试注销经过身份验证的用户,但我得到:

Controller.php 第 283 行中的 BadMethodCallException:方法 [getLogout] 不存在。

在 AuthController.php 中我说:

public function getLogout() {
        parent::getLogout();
        Auth::logout();
    }

在 routes.php 中

Route::get('auth/logout', 'Auth\AuthController@getLogout');

这是welcome.blade.php中的HTML

<a href="auth/logout">Logout</a>

我做错了什么?

【问题讨论】:

    标签: php laravel laravel-5.1 logout laravel-routing


    【解决方案1】:

    getLogout is a method on the AuthenticatesUsers trait,不在控制器的父级上。

    完全删除您的 getLogout 方法,一切都会按预期工作。

    【讨论】:

    • 哦,是的,它确实有效。非常感谢。我认为我必须创建一个新的 AuthenticatesUsers 子方法并将 Auth::logout();因为在 laravel 的文档中它说:要将用户从您的应用程序中注销,您可以使用 Auth 外观上的 logout 方法。这将清除用户会话中的认证信息
    • @Alex - 正如你在 trait 的 getLogout 方法中看到的那样,it calls Auth::logout() for you
    • @JesephSilber 是的,我看到了。我真的没想到 Laravel 会为我做这些。再次感谢!
    猜你喜欢
    • 2016-04-06
    • 2016-04-03
    • 1970-01-01
    • 2016-08-23
    • 2020-12-07
    • 2018-03-30
    • 2016-02-13
    • 2016-02-28
    • 2021-06-15
    相关资源
    最近更新 更多