2016-03-06 63 views
1

首先相当初学者,所以这对我来说都是非常新的,我不知道如何思考以寻求帮助。Laravel 5.2 Auth :: check()在注册后工作,但在注销和登录后不起作用

我有旧网站的数据库已经有用户表,所以我使用旧的数据库,并与laravel集成。我创建了所需的额外字段给用户表需要和跑:

php artisan make:auth 

后来注册很好。如果我没有注销,用户将被创建并且Auth :: check会识别用户。

但是,如果我注销并使用刚刚创建的用户重新登录,则Auth :: check不再识别用户。

我在config/auth.php上没有触及任何东西,除了/User.php模型没有做任何更改以将其链接到旧数据库。

我注意到的另一件奇怪的事情是,artisan make:auth似乎没有创建route.php的任何路由,这是正常的吗?它在哪里得到根源在这种情况下?

可能是什么问题?任何帮助将不胜感激!

回答

2

确保您访问auth :: check的路由在web中间件内。 您的注册/登录/ resetpassword路线是Route::Auth();

您的组应该是这样的:

Route::group(['middleware' => 'web'], function() { 
     Route::auth(); 
     Route::get('/home', '[email protected]'); 

     Route::get('/', function() { 
     return view('welcome'); 
     }); 

}); 

如果路线:: AUTH()不为您解决问题,手动添加

 // Authentication Routes... 
     $this->get('login', 'Auth\[email protected]'); 
     $this->post('login', 'Auth\[email protected]'); 
     $this->get('logout', 'Auth\[email protected]'); 

     // Registration Routes... 
     $this->get('register', 'Auth\[email protected]'); 
     $this->post('register', 'Auth\[email protected]'); 

     // Password Reset Routes... 
     $this->get('password/reset/{token?}', 'Auth\[email protected]'); 
     $this->post('password/email', 'Auth\[email protected]'); 
     $this->post('password/reset', 'Auth\[email protected]'); 
+1

谢谢。为答案。我其实已经完全像你所描述的那样。不知道Route :: auth()会自动获取这些路由,但实际上我发现了这个问题。由于某种原因,即使我在模型中定义它,用户表的增量ID也必须是id。我有它的ID(大写字母),并导致了这个问题。我把它变成了小写字母,噗的一声,问题消失了。 – EmJeiEn