且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 5.3如何在通知电子邮件中显示用户名

更新时间:2023-02-17 09:38:20

尝试一下:

用户模型:

User Model:

public function sendPasswordResetNotification($token) {
    return $this->notify(new PasswordReset($token, $this->username));
}

App \ Notifications \ PasswordReset:

App\Notifications\PasswordReset:

class PasswordReset extends Notification
{
    use Queueable;

    public $username;

    public function __construct($token, $username)
    {
        $this->username = $username;
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->greeting('Hello '.$this->username.',')
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', 'https://laravel.com')
                    ->line('Thank you for using our application!');
    }
}