Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.2-Auth::trunt()方法不会持久地登录用户_Php_Laravel_Session_Authentication - Fatal编程技术网

Php Laravel 5.2-Auth::trunt()方法不会持久地登录用户

Php Laravel 5.2-Auth::trunt()方法不会持久地登录用户,php,laravel,session,authentication,Php,Laravel,Session,Authentication,我正在尝试手动登录并在我的网站中注册用户,遵循中的说明,当我尝试使用正确的凭据登录注册用户时,Auth::trunt()登录用户并返回true,但是用户在后续请求中丢失 以下是用于登录用户的控制器: public function login() { $username = Request::input('username'); $password = Request::input('password'); if (Auth::attempt(['username' =

我正在尝试手动登录并在我的网站中注册用户,遵循中的说明,当我尝试使用正确的凭据登录注册用户时,
Auth::trunt()
登录用户并返回true,但是用户在后续请求中丢失

以下是用于登录用户的控制器:

public function login() {
    $username = Request::input('username');
    $password = Request::input('password');

    if (Auth::attempt(['username' => $username, 'password' => $password])) {
      return redirect()->route('accounts', [$username]);
    } else {
      return redirect('/');
    }
  }
重定向到用户页面后,没有用户会话

在检查会话是否正常工作(我正在使用数据库驱动程序)后,我注意到Laravel在执行
Auth::trunt()
之后立即将会话数据创建到数据库中,但是
user\u id
字段为
NULL
,这就是用户不保持登录的原因。“我的用户”表包含所有必需的字段,只有3个附加字段(
first\u name
last\u name
username
)。我无法理解为什么
trunt()
方法在成功验证用户凭据后没有正确创建用户会话,即使会话工作正常

编辑:即使使用AuthController方法创建和登录用户,它也不起作用,我得到相同的结果,一个没有
user\u id
信息的会话。什么可能导致会话/身份验证出现这种行为