Change USER Model Primary key ID to another in Laravel Passport

后端 未结 2 1566
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-26 07:42

I have a project where I have changed the User model primary key from \"id\" to \"MemberX\" using the following command in my User.php model file:

protected $primaryKey

2条回答
  •  旧时难觅i
    2021-01-26 08:20

    Maybe you should check if the driver on the laravel/config/auth.php has eloquent instead of database?

    'providers' => [
            'users' => [
                'driver' => 'eloquent', //instead of database
                'model' => App\User::class,
            ],
    

    database uses DatabaseUserProvider which the find method only looks on the id column.

    eloquent uses EloquentUserProvider which the find method looks at the primary key if $primaryKey is defined before looking at id.

提交回复
热议问题