首先是初学者,所以这一切对我来说都是很新的,我没有想法,所以想寻求一些帮助。
我有来自旧站点的数据库,该数据库已经有其用户表,所以我正在使用旧数据库并将其与 laravel 集成。我为用户表创建了所需的额外字段并运行:
php artisan make:auth
之后注册效果很好。用户已创建,如果我不注销,Auth::check 会识别用户。
但是,如果我注销并使用刚刚创建的用户重新登录,Auth::check 将无法再识别该用户。
我没有涉及配置/身份验证的任何内容.php并且除了/User.php 模型将其链接到旧数据库之外没有进行任何更改。
我注意到的另一件奇怪的事情是,工匠make:auth似乎没有创建任何路线.php,这正常吗?在这种情况下,它从哪里得到根源?
可能是什么问题?任何帮助将不胜感激!
确保您为 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');