我通过创建一个函数并将类插入到模型中,将发送到实体的每封电子邮件保存到数据库中。一切正常,主要目标是在收件人收到消息时完全按原样显示消息,并将我作为 发送的所有消息检索到页面。为了更容易地在foreach循环中检索每个特定消息的呈现,我认为最好从模型中获取它。storeEmailMailMessageEmailMessageUser
这是我的通知类:
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
我的类扩展Illuminate\Notifications\Notification
我正在保存(新邮件消息)在$email->mail = $mail;
如何显示邮件通知,就像我发送它时一样?对此的最佳解决方案是什么?提前致谢
一只名叫tom的猫