简体   繁体   English

如何在 laravel Jetstream 中从自定义 controller 创建新用户

[英]how to create new user from custom controller in laravel Jetstream

I am working on custom controller that will allow the admin of the system to create new user我正在开发自定义 controller,这将允许系统管理员创建新用户

so far i did the below for store function:到目前为止,我为商店 function 做了以下操作:

public function store(Request $request)
{
    $validatedData = $request->validate([
        'name' => 'required|max:255',
        'email' => 'required',
        'password' => 'required',
        'role' => 'required',
        'department' => 'required',
    ]);
    $user = User::create($validatedData);

    return redirect('add-staff')->with('success', 'User is successfully saved');
}

the above function will create new user in users database but i can't login with the new created user and it will show un-hashed password in the databse上面的 function 将在用户数据库中创建新用户,但我无法使用新创建的用户登录,它会在数据库中显示未散列的密码

is there a way to create new user with jetstream from custom controller?有没有办法从自定义 controller 创建新用户?

It is because you never hash the password, one way of solving this would be to add before the User::create the following line:这是因为您从来没有 hash 密码,解决此问题的一种方法是在User::create之前添加以下行:

$validatedData['password'] = Hash::make($validatedData['password']);

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

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