Change USER Model Primary key ID to another in Laravel Passport

后端 未结 2 1562
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  • 2021-01-26 07:56

    Add this code to your User model

    {
       return $this->hasMany(Passport::clientModel(), 'user_id', 'MemberID');
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题