简体   繁体   English

如何将hash密码添加到数据库?

[英]How to add hash password to database?

I have store() in controller, and in this place I call 3 functions.我在 controller 有store() ,在这个地方我调用了 3 个函数。 Variable $users store correct fields validation with values them.变量$users使用值存储正确的字段验证。 In next step I call function which hash password.在下一步中,我调用 function 密码 hash。 At the end I call function which add user to database.最后我调用 function 将用户添加到数据库。 My problem is that hash password is not add to database.What can I do that pass hashPassword to createUser() ?我的问题是 hash 密码没有添加到数据库中。我该怎么做才能将 hashPassword 传递给createUser()

 public function store(RegistrationRequest $request, UserService $user)
{
     $user = $request->correctValidate();  
     $userService->hashPassword($user['password']);
     $userService->createUser($user);
}

public function createUser($request): void
{
    User::create($request);
}

public function hashPassword($request)
{
    return Hash::make($request);
}

public function correctValidate()
{
    return $this->validated();
}

@Deks2 Please try below solution: @Deks2 请尝试以下解决方案:

$user['password'] = $userService->hashPassword($user['password']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM