0

我正在尝试将用户详细信息传递给我的通知,以便我可以说:亲爱的用户名,但无法弄清楚如何。另外,我期待在验证用户时获得默认 URL。所以,基本上我只想更改我的 toMail 函数中的第一个 ->line() 。

在用户模型中:

public function sendEmailVerificationNotification()
{
    $this->notify(new CustomVerifyEmail($this->user));
}

在 CustomVerifyEmail 类中

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

    /**
     * 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)
                    ->line('The introduction to the notification.'.$this->user->email)
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

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

1 回答 1

0

假设它将是您的模型,您应该能够从$notifiable传递给调用的中获取“名称”:toMailUser

line('The introduction to the notification.'. $notifiable->name)

对于自定义MailMessage发送的方法,我已经为您的其他问题添加了答案。Laravel Auth,获取 Notification 中传入的默认 URL

于 2019-11-17T04:49:50.257 回答