2016-02-10 82 views
1

我在我的Laravel 5.2应用程序中使用认证。一切都好,但注销不起作用。任何人都可以向我解释,为什么它发生?Laravel 5.2不能注销

routes.php文件

Route::group([ 

    'middleware' => ['web'] 

], function() { 

     Route::get('auth/login', 'Auth\[email protected]'); 
     Route::post('auth/login', 'Auth\[email protected]'); 
     Route::get('auth/logout', 'Auth\[email protected]'); 
     ... 
}); 

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 : '/'); 
    } 
    ... 
} 

回答

3

希望这是工作

您在控制器的方法名是错误的。

1)

public function logout() 

替换用这种方法

public function getLogout() 

说明----------------------- -----------------

在路线您用过以下航线

Auth\[email protected] 

你使用以下

public function logout() 

方法名称的方法仅仅是注销和路由具有getLogout所以这种方法不是在验证控制器找到这么注销不工作。


2) 另一种方式是使用此唯一。

public function __construct() 
{ 
    $this->middleware('guest', ['except' => 'getLogout']);   
} 

并删除注销方法。

Thnaks

+0

你当然对,谢谢。但是另外,这行必须是'$ this->中间件('guest',['除'=> ['logout','getLogout']]);'。 – Evgeniy

+0

然后你可以尝试我的答案的第二个选项。希望这是工作.. –