找不到路线-logout

时间:2016-05-26 21:37:06

标签: laravel laravel-5 laravel-5.1

我试图点击退出按钮,但它会返回错误:

NotFoundHttpException in RouteCollection.php line 161:

Authcontroller中没有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>

1 个答案:

答案 0 :(得分:1)

尝试

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

或者为您的路线命名

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

并做

<a href="{{route('logout')}}">Logout</a>