Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

so far i did the below for store 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

is there a way to create new user with jetstream from custom controller?

>Solution :

It is because you never hash the password, one way of solving this would be to add before the User::create the following line:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading