[英]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.我有一个 Laravel 7 应用程序,并使用 Laravel AUTH 脚手架进行登录/注册/身份验证。
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 :我看到 Laravel 有一些与内置身份验证相关的事件,例如在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.非常感谢任何帮助。
As suggested by @lagbox I simply did the following:正如@lagbox 所建议的,我只是做了以下事情:
$user = \App\User::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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.