Laravel更改用户表的默认主键 [英] Laravel change default primary key of users table
本文介绍了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更改用户表的默认主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文