发送带有标记后的降价显示Laravel通知(MailMessage)

问题描述 投票:0回答:1

我通过创建函数storeEmail将发送给实体的每封电子邮件保存到数据库中,并将MailMessage类插入到EmailMessage模型中。一切工作正常,主要的[[goal是在收件人收到消息后完全显示该消息,并将我以User格式发送的所有消息检索到页面上。为了更容易在foreach循环中检索每个特定Message的呈现,我认为最好从Model中获取它。

这是我的通知类:

class SimpleEmail extends Notification { use Queueable; private $link; private $user; /** * Create a new notification instance. * * @return void */ public function __construct($link) { $this->link = $link; $this->user = Auth::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) { $mail = (new MailMessage) ->from($this->user->email, $this->user->name) ->subject('My Dummy Subject') ->greeting('To: '.$notifiable->email) ->action('Action Button', url($this->link)) ->line('Thank you for reading my message') ->salutation('Friendly, '.$this->user->name); $this->storeEmail($mail,$notifiable); return $mail; } public function storeEmail($mail,$notifiable){ $email = new EmailMessage; $email->sender_type = 'App\User'; $email->sender_id = $this->user->id; $email->mail = $mail; $email->save(); $notifiable->email_messages()->save($email); } }

[Note:

    我正在使用Illuminate\Notifications\Messages\MailMessage
  1. 我的课程扩展了Illuminate\Notifications\Notification
  2. 我在$ email-> mail = $ mail中保存(新的MailMessage);
  • 我试图dd($email->mail);,我得到了:

    ^ array:20 [▼ "view" => null "viewData" => [] "markdown" => "notifications::email" "theme" => null "from" => array:2 [▶] "replyTo" => [] "cc" => [] "bcc" => [] "attachments" => [] "rawAttachments" => [] "priority" => null "callbacks" => [] "level" => "info" "subject" => "My Dummy Subject" "greeting" => "To: Dohn John" "salutation" => "Friendly, Nikolas Diakosavvas" "introLines" => array:2 [▶] "outroLines" => array:1 [▶] "actionText" => "Action Button" "actionUrl" => "http://my-example-url.com ▶"

  • 如何显示邮件通知,就像发送邮件时一样?最佳的解决方案是什么?谢谢,提前

    编辑

    已成功使用此代码呈现MailMessage

    works

    $email = EmailMessage::first(); return (new \App\Notifications\SimpleEmail('my-link', $email->recipient->assignto))->toMail($email->recipient);

    但这并不是我想要的

    ,因为每次我需要查找:
      每封电子邮件都使用哪个Notification类,以便我可以呈现它。
    1. 每个通知类的变量。]​​>
  • 我通过创建一个功能storeEmail将发送给实体的每封电子邮件保存到数据库中,并将MailMessage类插入到EmailMessage模型中。一切正常,主要目标是...
  • php laravel laravel-5 laravel-5.8 laravel-notification
    1个回答
    0
    投票
    为了完成此任务:
    © www.soinside.com 2019 - 2024. All rights reserved.