在laravel 5.3中进行密码重置时,如何将电子邮件地址附加到URL

时间:2016-12-14 10:00:11

标签: php laravel notifications laravel-5.3 laravel-mail

我要在重置密码时在网址中附加用户的电子邮件地址,因此重置网址将如下所示http://blog.dev/password/reset/4cfbb048346474aab7080c88f16c34b9ea377b9ea35804387216fce303a38855?email=test%40gmail.com

但是我收到错误FatalErrorException in CustomResetPassword.php line 54: Call to undefined method App\Notifications\CustomResetPassword::getEmailForPasswordReset()

我通过自定义通知类发送重置电子邮件,代码如下     

namespace App\Notifications;


use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;


class CustomResetPassword extends Notification
{
use Queueable;


public $token;



/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct($token)
{
    $this->token = $token;

}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['mail'];
}

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
     return (new MailMessage)
        ->subject('Reset Password')
        ->line('You are receiving this email because we received a password reset request for your account.')
        ->action('Reset Password', url('password/reset', $this->token).'?email='.urlencode($this->getEmailForPasswordReset()))
        ->line('If you did not request a password reset, no further action is required.');
}

/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toArray($notifiable)
{
    return [
        //
    ];
}
}

我在这里错过了什么吗?

1 个答案:

答案 0 :(得分:0)

$this指的是您的实际课程,您尝试使用getEmailForPasswordReset CustomResetPassword方法但这种方法并不存在。

您可以像发送令牌一样将电子邮件传递给notification