Laravel 5.3 通知与可邮寄
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40683957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.3 Notification Vs Mailable
提问by Neel
I am a little confused about whether to use Laravel's Notificationor Mailableclass. From what I understand, Mailables are used to send only emails whereas Notifications can be used to send emails and sms. In my application, I dont have plans to send sms notifications for now, so I am confused if I should just use the Mailable class in this case. My questions are:
我对是否使用 Laravel 的Notification或Mailable类有点困惑。据我了解,Mailables 仅用于发送电子邮件,而 Notifications 可用于发送电子邮件和短信。在我的应用程序中,我暂时没有发送短信通知的计划,所以我很困惑在这种情况下是否应该只使用 Mailable 类。我的问题是:
If I am only going to be sending emails notifications, is it better for me to use Mailables instead of Notifications?
If each emails have different html layout, then would Mailable be the better option?
Even if all emails are Notification emails in nature, does it still make sense to send them using Mailables instead of Notifications?
如果我只想发送电子邮件通知,使用 Mailables 而不是 Notifications 对我来说更好吗?
如果每封电子邮件都有不同的 html 布局,那么 Mailable 会是更好的选择吗?
即使所有电子邮件本质上都是通知电子邮件,使用 Mailables 而不是通知发送它们仍然有意义吗?
Can someone tell me the main difference between these 2 and how should we decide on which method to choose when sending emails in Laravel 5.3.
有人可以告诉我这 2 个之间的主要区别,以及我们应该如何决定在 Laravel 5.3 中发送电子邮件时选择哪种方法。
采纳答案by Juliatzin
Yes, definitively, if each email layout is different, you should use Mailable
是的,明确地说,如果每个电子邮件布局不同,您应该使用 Mailable
Mailable is the new way to send emails, easier than before. More customizable than Notifications.
Mailable 是一种新的电子邮件发送方式,比以前更容易。比通知更可定制。
Notification is very nice if you want to send a predefined layout in differents channel ( Mail, SMS, Slack, etc )
如果您想在不同的频道(邮件、短信、Slack 等)中发送预定义的布局,通知非常好
You can customize notifications layout, but having 1 layout by notification is going to get more difficult... it is just not the use case for notifications
您可以自定义通知布局,但是通过通知拥有 1 个布局会变得更加困难……这不是通知的用例
回答by patricus
Although it is not in the documentation, as of Laravel 5.3.7, the Notifications mail
channel can work with Mailable
objects in addition to the notification MailMessage
objects.
虽然它不在文档中,但从 Laravel 5.3.7 开始,除了通知对象之外,通知mail
通道还可以处理对象。Mailable
MailMessage
Therefore, you can create all your emails as Mailable
objects, and if you decide to send them via Notifications, you would just have your toMail()
method return the Mailable
objects you've already made.
因此,您可以将所有电子邮件创建为Mailable
对象,如果您决定通过通知发送它们,您只需让您的toMail()
方法返回Mailable
您已经创建的对象。