2016-02-25 23 views
2

我可以成功作为用户登录,但它仍然以guest身份接收身份验证。我无法注销或登录,因为它会将我重定向到主页。我使用内置的身份验证前期的users.The唯一的文件我已经改变了与此有关的问题是路由文件laravel身份验证总是客人

Route::get('/', function() { 
// return view('welcome'); 
if (Auth::check()) { 
    return Auth::user(); 
} 
else 
{ 
    return 'guest'; 
} 
}); 

Route::group(['middleware' => ['web']], function() { 
// Authentication routes... 
Route::get('auth/login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 

// Registration routes... 
Route::get('auth/register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 
Route::get('auth/logout', 'Auth\[email protected]'); 

}); 
+1

将您的“/”路线移动到网络中间件。 – Alen

+0

谢谢你的工作。 –

回答

2

中间件网络所以没有会话你,因为权威性不活动检查AUTH启动会议使用会话。

Route::group(['middleware' => ['web']], function() { 

Route::get('/', function() { 
// return view('welcome'); 
if (Auth::check()) { 
    return Auth::user(); 
} 
else 
{ 
    return 'guest'; 
} 
}); 
// Authentication routes... 
Route::get('auth/login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 

// Registration routes... 
Route::get('auth/register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 
Route::get('auth/logout', 'Auth\[email protected]'); 

});