【发布时间】:2017-06-19 17:40:08
【问题描述】:
我创建了一个通知类来向客户发送订单确认电子邮件。在此,我想从他们的订单中添加详细信息,这是来自 eloquent 的集合。我在通知类中有数据。 (如果我 dd($this->order) 我得到了预期的结果。)
我的问题是将数据从类传递到电子邮件刀片模板。我已经通读了文档,但没有任何东西可以让我用来传递整个集合,然后能够在视图中对其进行格式化。
这是我的OrderConfimation 课程
class OrderConfirmation extends Notification
{
use Queueable;
public $order;
public $user;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($user , $order)
{
$this->order = $order;
$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)
->subject('Order Confirmation ['.$this->order->ID.']')
->greeting('Hi '.$this->user->F_NAME)
->line('Thank you for ordering from Awesome Store.')
->line('Once Payment has been confirmed we will send you a Payment Confirmation Email')
->line('As your order progresses we will send you updates. You can also track your order status by viewing it on our site at anytime')
->action('View Order', 'order url here')
->line('Thank you for shopping with us!');
/**** What do i use here to pass $this->order to the view ????****/
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
我觉得答案会很简单,因为它是 laravel,我只是想念它
【问题讨论】:
-
只是出于好奇,您为什么使用
Notification类来发送电子邮件。为什么不创建一个Mailable类? laravel.com/docs/5.3/mail#writing-mailables -
在阅读了关于通知的信息后,这对我来说很有意义。我对 laravel 还是很陌生,所以我不知道我可以使用
Mailable。那我可能误解了通知的使用吗?
标签: php laravel email laravel-5.3