我正在尝试在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中自定义忘记密码的电子邮件
发布评论