【发布时间】:2020-04-20 19:08:43
【问题描述】:
我希望注册后的激活链接发送到一个电子邮件,这是因为我不希望每个人都创建一个管理员帐户,所以任何人创建一个管理员帐户应用程序的所有者将通过点击激活来激活他的帐户他的电子邮件(所有者电子邮件)上的链接。
protected function postAdminRegistration(Request $request)
{
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
try {
$validatedData['password'] = bcrypt(array_get($validatedData, 'password'));
$validatedData['activation_code'] = str_random(30).time();
$user = app(User::class)->create($validatedData);
} catch (\Exception $exception) {
logger()->error($exception);
return redirect()->back()->with('message', 'Unable to create new user.');
}
$user->notify(new UserRegisteredSuccessfully($user));
return redirect()->route("user.loginform")->withSuccess('Successfully created a new account.
Please check your email and activate your account.');
}
用户注册成功
public function toMail($notifiable)
{
$user = $this->user;
return (new MailMessage)
->from('****@gmail.com')
->subject('Successfully created new account')
->greeting(sprintf('Hello %s', $user->fname))
->line('You have successfully registered to our system. Please activate your account.')
->action('Click Here',
route('user.activate', $user->activation_code))->line('Thank you for using our application!');
}
型号
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name','email','password'
];
protected static $logFillable = true;
protected $hidden = [
'password', 'remember_token',
];
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token.'/'.$this->email));
}
}
【问题讨论】:
-
您的意思是将激活链接发送到特定的电子邮件?那么您必须添加此电子邮件
-
我必须把这封电子邮件放在哪里?之后->来自('****@gmail.com')?
-
我认为这是您获取电子邮件的唯一途径
-
有什么更新吗?
-
@FaragHalain 您要将激活电子邮件发送给谁(发送至
owner of the app或`注册用户`)?