Laravel 5.2 未注销
Laravel 5.2 not logout
我在 Laravel 5.2 应用程序中使用身份验证。一切正常,但注销不起作用。谁能给我解释一下,为什么会这样?
routes.php
Route::group([
'middleware' => ['web']
], function () {
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
...
});
Controller.php
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
public function __construct()
{
$this->middleware('guest', ['except' => 'logout', 'getLogout']);
}
public function logout()
{
/* This place not trigger */
echo 'Logout';
exit;
Auth::guard($this->getGuard())->logout();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
...
}
希望这是工作
您在控制器的方法名称中输入错误。
1)
public function logout()
用这个方法替换
public function getLogout()
说明-------------------------------------
您在路线中使用了以下路线
Auth\AuthController@getLogout
并且您使用了
之后的方法
public function logout()
方法名称只是注销,路由有 getLogout,因此在 Auth 控制器中找不到此方法,因此注销无法正常工作。
2)
另一种方法是只使用它。
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
并删除注销方法。
谢谢
我在 Laravel 5.2 应用程序中使用身份验证。一切正常,但注销不起作用。谁能给我解释一下,为什么会这样?
routes.php
Route::group([
'middleware' => ['web']
], function () {
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
...
});
Controller.php
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
public function __construct()
{
$this->middleware('guest', ['except' => 'logout', 'getLogout']);
}
public function logout()
{
/* This place not trigger */
echo 'Logout';
exit;
Auth::guard($this->getGuard())->logout();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
...
}
希望这是工作
您在控制器的方法名称中输入错误。
1)
public function logout()
用这个方法替换
public function getLogout()
说明-------------------------------------
您在路线中使用了以下路线
Auth\AuthController@getLogout
并且您使用了
之后的方法public function logout()
方法名称只是注销,路由有 getLogout,因此在 Auth 控制器中找不到此方法,因此注销无法正常工作。
2) 另一种方法是只使用它。
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
并删除注销方法。
谢谢