Auth :: attempt()仅返回false

时间:2019-02-08 08:33:03

标签: laravel

我想使用手动身份验证,但是我的代码只返回“ false”

登录代码:

if (Auth::attempt(['username' => "myusername" , 'password' => '654321'])){
            return 'true';
        }else return 'false';

我用以下代码注册用户:

$user = new User();
        $user->username = $request->username;
        $user->password = bcrypt($request->password);
        $user->api_token = $this->makeToken();
        $user->save();

我更改密码的键名以查看查询:

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'passsword' in 'where clause' (SQL: select * from `users` where `username` = mohammad and `passsword` = 654321 limit 1)"

用户名和密码不在查询中!

2 个答案:

答案 0 :(得分:1)

首先,为什么要使用字符串作为用户名myusername和密码654321的凭据?

将您的myusername654321更改为:

if (Auth::attempt(['username' => request('username') , 'password' => request('password')])){
  return 'true';
}else return 'false';

还要确保username中的passwordrequest()是您帖子的name

答案 1 :(得分:0)

只需在用户模型中添加extends Illuminate\Foundation\Auth\User

问题解决了。