Laravel:从邮件模板中获取电子邮件收件人 [英] Laravel: get email recipient from within the mail template

查看:141
本文介绍了Laravel:从邮件模板中获取电子邮件收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel(5.5)中使用通知时,可以从toMail()方法中访问可通知的(收件人).

When using Notifications in Laravel (5.5), you can access the Notifiable (the recipient) from within the toMail() method.

发送邮件时,是否有等效的方法来访问收件人?

Is there an equivalent way to access the recipient when you are sending a Mailable?

有没有比这样重复构造器中的User实例更好的解决方案了?

Is there a better solution than just repeating the User instance in the constructor like this?

Mail::to($user)->send(new EventAlert($user));

推荐答案

不,没有办法.但是您可以在Notification类中使用Mailable,并在控制器或服务中使用通知而不是Mailable.

No, there is no way. But you can use Mailable inside a Notification class and use the notification instead of Mailable in a controller or service.

来自文档:

您可以从toMail方法返回一个可邮寄对象

You may return a mailable object from the toMail method

public function toMail($notifiable)
{
    return (new Mailable($this->invoice))->to($this->user->email);
}

这篇关于Laravel:从邮件模板中获取电子邮件收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆