我可以在 Notification Laravel 中从数据库中获取电子邮件数据吗?

Can I get a email data from Database in Notification Laravel?

编辑:我想要的是在电子邮件通知中显示新的订阅者电子邮件。我想让那些存储在数据库中的电子邮件显示在下面的电子邮件表格中。

在您有新订阅者这句话之后: 它将显示新订阅者的新电子邮件

这是我的通知

public function toMail($notifiable)
{
    $subscribers = Subscribe::where('email', '!=', null)->first();

    return (new MailMessage)
                ->subject('You have a new subscriber')
                ->line('You have a new subscriber:', $subscribers)
                ->action('Click Here', url('/subscribe'));
                // ->line('Thank you for using our application!');
}

我怎样才能完成这项工作?

*对不起我的英语不好

你的脚本有一些小问题:

在此处将 逗号 更改为

->line('You have a new subscriber:', $subscribers)

获取对象的电子邮件 属性。像这样:

$subscribers->email;

如果您想获得最新订阅者(并且您 table 包含 laravel 时间戳)

Subscribe::where('email', '!=', null)->orderBy('created_at','DESC')->first();

综上所述,您的代码应该如下所示:

public function toMail($notifiable)
{
    $subscribers = Subscribe::where('email', '!=', null)->orderBy('created_at','DESC')->first();

    return (new MailMessage)
                ->subject('You have a new subscriber')
                ->line('You have a new subscriber:'.$subscribers->email)
                ->action('Click Here', url('/subscribe'));
                // ->line('Thank you for using our application!');
}