Reputation: 125
I'm using multi auth for Laravel ...
This is my lougout function for users
LoginController
public function logout()
{
Auth::guard('web')->logout();
return redirect('/');
}
AdminloginController
public function logout()
{
Auth::guard('web')->logout();
return redirect('/');
}
This is my route
Route::get('/enseignant/logout', 'Auth\LoginController@Elogout')->name('enseignant.logout');
Route::get('/administration/logout', 'Auth\AdminloginController@logout')->name('admin.logout');
All the methods in the view
<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>
The function works fine but when I click the button I get this error :
MethodNotAllowedHttpException in RouteCollection.php line 233
Upvotes: 1
Views: 1235
Reputation: 1833
Your route accepts only GET
method, but in the form, you specified using POST
. I think this is the source of the problem. The error message also indicates that.
It's recommended to use POST for logout, as you did. So, just by changing the route in question to...
Route::post(...);
... should fix the error.
Upvotes: 2