【问题标题】:Laravel Passport Overriding Primary key is not workingLaravel Passport 覆盖主键不起作用
【发布时间】:2020-11-11 12:04:13
【问题描述】:
  1. 我使用 user_sk 作为用户表中的主键
  2. 当使用护照进行身份验证时,它不会覆盖模型中的主键
  3. 用户模型已保护 $primaryKey = 'user_sk';

它总是显示这样的错误

"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from `users` where `id` = 32 limit 1)"

【问题讨论】:

    标签: laravel laravel-7 laravel-7.x


    【解决方案1】:

    这似乎是一个关系破坏了你的代码,基于以下question,这不能被标记为重复,因为问题没有接受答案。

    将以下内容添加到您的 User.php 模型中,看看是否有帮助。

    public function clients() {
        return $this->hasMany(Passport::clientModel(), 'user_id', 'user_sk');
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-12
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      • 2014-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多