Laravel Larvel 5.4:JWTAuth,EloquentUserProvider.php中的ErrorException

Laravel Larvel 5.4:JWTAuth,EloquentUserProvider.php中的ErrorException,laravel,laravel-5.4,Laravel,Laravel 5.4,我是拉威尔的新手,所以这可能是我的错误。使用laravel与验证用户。我正在观看本教程,并遵循每个步骤,安装tymon软件包并登录用户。但我得到了这个错误。我在下面发布了代码,如果您需要其他文件中的更多代码,请告诉我 EloquentUserProvider.php第120行中的ErrorException:传递了参数1 要照亮\Auth\EloquentUserProvider::validateCredentials,必须 Lightlight\Contracts\Auth\Authenti

我是拉威尔的新手,所以这可能是我的错误。使用laravel与验证用户。我正在观看本教程,并遵循每个步骤,安装tymon软件包并登录用户。但我得到了这个错误。我在下面发布了代码,如果您需要其他文件中的更多代码,请告诉我

EloquentUserProvider.php第120行中的ErrorException:传递了参数1 要照亮\Auth\EloquentUserProvider::validateCredentials,必须 Lightlight\Contracts\Auth\Authenticatable的实例,的实例 应用程序\用户给定

这是我的用户模型:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

    class User extends Model
    {
        protected $hidden = ["password"];
        protected $fillable = [
                                "id",
                                "name",
                                "password",
                                "mobile_number",
                                "gender",
                                "age",
                                "company_name",
                                "profile_image",
                                "email"
                            ];
    }
?>
my UsersController中的用户存储函数:

public function store(Request $request)
    {
        $payload = json_decode($request->payload, true);

        $validator = Validator::make($payload, $this->rules);

        if ($validator->passes()) {

            $user = (new User())->fill($payload);
            if($user->save()){

                $response = [
                    "msg" => "User created",
                    "link" => "/api/users/" . $user->id
                ];
                return response()->json($response, 200);
            }

            $response = [
                "msg" => "An error occured"
            ];

            return response()->json($response, 404);

        } 
        else {
            return response()->json($validator->messages(), 404);
        }        
    }
在存储用户请求时,有效负载是键,值是json对象,下面给出了小样本对象:

payload={
  "name": "Alexa",
  "email": "alexa@gmail.com",
"password":"12345",
  "gender": "Male",
  "age": 24
}
将此添加到您的模型中

use Illuminate\Foundation\Auth\User as Authenticatable;
换一条线

class User extends Authenticatable
编辑: 看起来你在用明文存储密码。将其添加到您的用户模型中

public function setPasswordAttribute($value)
{
    $this->attributes['password'] = bcrypt($value);
}

一个与此错误无关的提示:从可填充字段中删除id,您不希望您的id是可签名的。您的密码应该只在隐藏数组中。不是去填充的。和它的凭据而不是凭据。我也尝试了此操作,错误已被删除,但如果输入正确的凭据,我始终会获得无效的凭据。在将用户添加到数据库的位置共享您的代码。我猜你是在直接存储明文密码。默认情况下,laravel的auth方法将密码输入散列以进行比较。我已更新帖子,您可以在上面看到我如何在数据库中添加用户。@MTA我编辑了我的答案,请检查它。您将以明文形式存储密码,而不是存储密码散列,但是当您使用JWT::Test时,它反过来会使用laravel内置的auth方法来比较输入密码的散列。因此,您会收到无效凭证错误。添加我显示的setPasswordAttribute。除了你链接的视频系列的第5集之外,还展示了如何使用bcrypt hasher。不知道你怎么会错过。
public function setPasswordAttribute($value)
{
    $this->attributes['password'] = bcrypt($value);
}