找不到路由-logout(Route is not found -logout)
我试图点击退出按钮,但它返回一个错误:
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>I am trying to click on logout button, but it returns an error:
NotFoundHttpException in RouteCollection.php line 161:There's no getLogout in Authcontroller, and it worked before, not sure why now it isn't.
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');view:
<a href="auth/logout">Logout</a>最满意答案
尝试
<a href="/auth/logout">Logout</a>或者给你的路线命名
Route::get('auth/logout', ['as' => 'logout', 'uses' => 'Auth\AuthController@getLogout');并做
<a href="{{route('logout')}}">Logout</a>Try
<a href="/auth/logout">Logout</a>Or give your route a name
Route::get('auth/logout', ['as' => 'logout', 'uses' => 'Auth\AuthController@getLogout');and do
<a href="{{route('logout')}}">Logout</a>更多推荐
发布评论