Laravel 5.2 Auth :: check()在注册后工作,但在注销和登录后没有

时间:2016-03-06 14:46:40

标签: php laravel authentication

首先是初学者,所以这一切对我来说都是新鲜事,而且我想出了一些想法可以提供一些帮助。

我有来自旧网站的数据库已经拥有它的用户表,所以我使用旧数据库并将其与laravel集成。我为所需的用户表创建了所需的额外字段并运行:

php artisan make:auth

之后注册效果很好。用户已创建,如果我不注销,Auth :: check会识别用户。

但是如果我退出并重新登录我刚创建的用户,Auth :: check就不会再识别用户了。

我在config / auth.php上没有触及任何内容,并且没有对/User.php模型进行任何更改以将其链接到旧数据库。

我注意到的另一个奇怪的事情是工匠制造:auth似乎没有创建到routes.php的任何路线,这是正常的吗?在这种情况下,它在哪里得到根源?

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

1 个答案:

答案 0 :(得分:2)

确保您为auth :: check访问的路由位于web中间件内。 您的注册/登录/重置密码路由在Route::Auth();

您的论坛应如下所示:

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

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

});

如果Route :: auth()没有为您修复,请手动添加

        // Authentication Routes...
        $this->get('login', 'Auth\AuthController@showLoginForm');
        $this->post('login', 'Auth\AuthController@login');
        $this->get('logout', 'Auth\AuthController@logout');

        // Registration Routes...
        $this->get('register', 'Auth\AuthController@showRegistrationForm');
        $this->post('register', 'Auth\AuthController@register');

        // Password Reset Routes...
        $this->get('password/reset/{token?}', 'Auth\PasswordController@showResetForm');
        $this->post('password/email', 'Auth\PasswordController@sendResetLinkEmail');
        $this->post('password/reset', 'Auth\PasswordController@reset');
相关问题