Skip to content
Advertisement

Laravel AUTH() – Adding additional users (without registration)

I’ve tried to find information on this and can’t find any. I have a Laravel 7 application and have used the Laravel AUTH scaffolding for login/registration/authentication.

I would like to allow a logged in user to add other users, I’ve done the simply but pushing the data in to the database (obviously no password is set) but now I would like to send an email to these users asking them to set a password and am unsure how to do this. I see Laravel has some events related to auth built in such as this called in the register function of RegistersUsers.php:

event(new Registered($user = $this->create($request->all())));

Can anyone confirm where I would need to create such an event and how I call it from the store function that adds the user to the database?

Any help much appreciated.

Advertisement

Answer

As suggested by @lagbox I simply did the following:

$user = AppUser::create([
            'firstname' => $validatedData['firstname'],
            'lastname' => $validatedData['lastname'],
            'email' => $validatedData['email'],
            'company_id' => $company_id,
            'phone_number' => $validatedData['phone_number'],
            'password' => Str::random(16),
        ]);

    event(new Registered($user));
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement