【发布时间】:2017-06-23 08:15:07
【问题描述】:
我正在开发 Laravel 5.4.24 中的身份验证系统。尝试注销时,我的浏览器出现错误:第 251 行的 RouteCollection.php 中的 MethodNotAllowedHttpException。
routes文件夹中web.php中的注销路由为:
Route::post('logout', 'Auth\LoginController@logout')->name('logout');
控制器存储的app/Http/LoginController.php代码如下:
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');
}
}
更新问题 下面的代码是我的 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>
【问题讨论】:
-
您能说明一下您是如何调用注销链接的吗?
-
@AlessandroMinoccheri 因为我使用 localhost 并将 laravel 保存在名为 sampleBlog 的目录中:我正在输入:localhost/sampleBlog/logout
-
@Patwan 这个 url localhost/sampleBlog/logout 是 get 方法,但在你的路由中定义是 post 方法
标签: php laravel-5.4