I am working on an authentication system in Laravel 5.4.24. I get an error on my browser when trying to logout: MethodNotAllowedHttpException in RouteCollection.php on line 251.
The logout route in web.php in routes folder is:
Route::post('logout', 'Auth\LoginController@logout')->name('logout');
The controller stored app/Http/LoginController.php has the following code:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
Updated Question The code below is my login.blade.php
@extends('main')
@section('title', '| login')
@section('content')
<div class='row'>
<div class='col-md-6 col-md-offset-3'>
{!! Form::open() !!}
{{ Form::label('email', 'Email:') }}
{{ Form::email('email', null, ['class' => 'form-control']) }}
{{ Form::label('password', 'Password:') }}
{{ Form::password('password', ['class' => 'form-control']) }}
<br>
{{ Form::checkbox('remember') }} {{ Form::label('remember', 'Remember Me:') }}
<br>
{{ Form::submit('Login', ['class' => 'btn btn-primary btn-block']) }}
{!! Form::close() !!}
</div>
</div>
@endsection
main.blade.php
<!DOCTYPE html>
<html lang="en">
<!-- Connection to the partials called _head.blade.php -->
@include('partials._head')
<body>
@include('partials._nav')
<!-- The below class container holds all body content-->
<div class='container'>
@include('partials._messages')
{{ Auth::check() ? "Logged In" : "Logged Out"}}
@yield('content')
@include('partials._footer')
</div> <!-- End of container -->
@include('partials._javascript')
@yield('scripts')
</body>
</html>