我有经典的用户 ID 表,其中主键是 BigIncrement。
我需要对用户隐藏 id 值。所以我的想法是使用 hashIds 包。我为屏蔽 id 所做的是在 id 列上创建 mutator:
public function getIdAttribute($id)
{
return Hashids::connection(User::class)->encode($id);
}
屏蔽效果很好,但是当我尝试登录时会出现问题。似乎未创建登录会话。
我的问题是:
- 为什么创建 id mutator 后登录失败?我假设要创建会话它涉及 id 值
- 除了使用 mutator 之外,还有什么更好的方法来屏蔽 id?