我希望注册后的激活链接发送到一封电子邮件,这是因为我不希望每个人都创建一个管理员帐户,因此任何人创建一个管理员帐户,应用程序的所有者都会通过单击他的激活链接来激活他的帐户。电子邮件(所有者电子邮件)。
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));
}
}
将此功能添加到用户模型,仅此而已
public function routeNotificationForMail($notification)
{
// Return email address only...
return '*****@gmail.com';
// Return name and email address...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句