Framework: logout failed for the post method is not allowed

Created on 27 Jun 2017  路  2Comments  路  Source: laravel/framework

Description:

logout failed, mentioned 'MethodNotAllowedHttpException'.
the problem can be fixed by modify the codes of the method named 'auth' in the file Illuminate/Routing/Router.php:

$this->post('logout', 'Auth\LoginController@logout')->name('logout');
======>
$this->get('logout', 'Auth\LoginController@logout')->name('logout');

then it works.

Steps To Reproduce:

/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public function auth()
{
// Authentication Routes...
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
$this->post('logout', 'Auth\LoginController@logout')->name('logout');
// Registration Routes...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');
// Password Reset Routes...
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');
}

Most helpful comment

logout is meant to be post to avoid csrf

you will need to make your logout button a form, rather than just a link

All 2 comments

logout is meant to be post to avoid csrf

you will need to make your logout button a form, rather than just a link

thank you very much for your reply!

Was this page helpful?
0 / 5 - 0 ratings