在Laravel 5.4中自定义忘记密码的电子邮件

编程入门 行业动态 更新时间:2024-10-27 18:20:31
本文介绍了在Laravel 5.4中自定义忘记密码的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在Laravel中自定义密码重置电子邮件.

I am trying to customize password reset email in Laravel.

我必须重写此功能:

namespace Illuminate\Auth\Passwords; use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification; use Illuminate\Http\Request; trait CanResetPassword { /** * Get the e-mail address where password reset links are sent. * * @return string */ public function getEmailForPasswordReset() { return $this->email; } /** * Send the password reset notification. * * @param string $token * @return void */ public function sendPasswordResetNotification($token) { $this->notify(new ResetPasswordNotification($token)); }

这是我的尝试:

public function sendPasswordResetNotification($token, Requests $request) { Mail::to($request->email)->send(new newpassword($token)); }

我收到此错误:

声明Illuminate \ Foundation \ Auth \ User :: sendPasswordResetNotification($ token,Illuminate \ Http \ Request $ request)必须与Illuminate \ Contracts \ Auth \ CanResetPassword :: sendPasswordResetNotification($ token)

Declaration of Illuminate\Foundation\Auth\User::sendPasswordResetNotification($token, Illuminate\Http\Request $request) must be compatible with Illuminate\Contracts\Auth\CanResetPassword::sendPasswordResetNotification($token)

推荐答案

如果您读取错误,则表明您的课程与 CanResetPassword 不兼容.如果你看着那......

If you read the error, it's telling you your class is not compatible with CanResetPassword. If you look at that....

interface CanResetPassword { /** * Get the e-mail address where password reset links are sent. * * @return string */ public function getEmailForPasswordReset(); /** * Send the password reset notification. * * @param string $token * @return void */ public function sendPasswordResetNotification($token); }

您可以看到函数 sendPasswordResetNotification 应该只接受一个参数,即 $ token .因此,您需要从方法的签名中删除 Request $ request 作为参数.

You can see the function sendPasswordResetNotification should only take one parameter, $token. So you need to remove Request $request as a parameter from the method's signature.

为了获取请求,您将需要在 sendPasswordResetNotification 方法内使用函数 request().

In order to get the request, you will want to use the function request() inside the sendPasswordResetNotification method.

public function sendPasswordResetNotification($token) { Mail::to(request()->email)->send(new newpassword($token)); }

更多推荐

在Laravel 5.4中自定义忘记密码的电子邮件

本文发布于:2023-11-16 04:43:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1601093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   忘记密码   电子邮件   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!