本文介绍了Laravel更改用户表的默认主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将默认主键从 users 表的 id 更改为 userId ,但是Laravel身份验证机制始终检查 users 表中的> id .示例:
I am trying to change the default primary key from id of users table to userId, but Laravel authentication mechanism always checks for id from users table. Example:
Users :: check()和Users :: attempt()
Users::check() and Users::attempt()
这些函数始终检查 users 表的 id 属性,以及如何更改Laravel的行为.
These functions always check for id attribute of users table, how to change this behavior of Laravel.
推荐答案要覆盖用于搜索的主键,必须在用户模型上定义primaryKey属性.
To override the primary key used to search you must define the primaryKey property on the User model.
protected $primaryKey = 'userId';更多推荐
Laravel更改用户表的默认主键
发布评论