找不到路线-登出

问题描述 投票:0回答:1

我试图单击注销按钮,但返回错误:

NotFoundHttpException in RouteCollection.php line 161:

getLogout中没有getLogout ,它以前也可以工作,不知道为什么现在不行。

AuthController:

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

        use AuthenticatesAndRegistersUsers, ThrottlesLogins;
        protected $redirectTo = "dashboard";
        protected $loginPath = 'auth/login';


    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'username' => 'required|max:20|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'username' => $data['username'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

Routes.php:

Route::get('auth/logout', 'Auth\AuthController@getLogout');

视图:

  <a href="auth/logout">Logout</a>
laravel laravel-5 laravel-5.1
1个回答
1
投票

尝试

<a href="/auth/logout">Logout</a> 

或者给你的路线起个名字

Route::get('auth/logout', ['as' => 'logout', 'uses' => 'Auth\AuthController@getLogout');

并做

<a href="{{route('logout')}}">Logout</a> 
© www.soinside.com 2019 - 2024. All rights reserved.