【问题标题】:Logout : MethodNotAllowedHttpException in RouteCollection.php line 233注销:RouteCollection.php 第 233 行中的 MethodNotAllowedHttpException
【发布时间】:2017-11-04 10:23:43
【问题描述】:

我正在为 Laravel 使用多重身份验证...

这是我为用户提供的 lougout 功能

登录控制器

public function logout()
{
    Auth::guard('web')->logout();
    return redirect('/');
}

管理员登录控制器

public function logout()
{
    Auth::guard('web')->logout();
    return redirect('/');
}

这是我的路线

Route::get('/enseignant/logout', 'Auth\LoginController@Elogout')->name('enseignant.logout');

Route::get('/administration/logout', 'Auth\AdminloginController@logout')->name('admin.logout');

视图中的所有方法

 <a href="{{ route('admin.logout') }}" class="btn btn-default btn-flat"
   onclick="event.preventDefault();
   document.getElementById('logout-form').submit();">
   Logout
 </a>

 <form id="logout-form" action="{{ route('admin.logout') }}" method="POST" style="display: none;">
 {{ csrf_field() }}
 </form>

该功能工作正常,但是当我单击按钮时出现此错误:

RouteCollection.php 第 233 行中的 MethodNotAllowedHttpException

【问题讨论】:

  • RouteCollection.php line 233 是什么?

标签: php laravel laravel-5


【解决方案1】:

您的路线只接受GET 方法,但在表单中,您使用POST 指定。我认为这是问题的根源。错误信息也表明了这一点。

建议像您一样使用 POST 进行注销。因此,只需将相关路线更改为...

Route::post(...);

...应该修复错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 2017-01-03
    • 2016-11-21
    • 2019-02-16
    • 2017-10-23
    • 2017-01-26
    • 2017-08-09
    相关资源
    最近更新 更多