duanlou2917 2018-11-23 02:48
浏览 109

Laravel使用Notification Facade,其中包含用户电子邮件参数

I am trying to send notification with a name or email parameter.

Controller

$subscriber = Subscribe::whereNotNull('verified')->get();
Notification::send($subscriber, new NotifySubscriber($post));

toMail function

public function toMail($notifiable)
{
    $url = url('/news/' . $this->post->slug);

    return (new MailMessage)
        ->greeting('Dear User')
        ->line('Title : ' . $this->post->title)
        ->action('Read More', $url)
}

I want ->greeting('Dear User') with user name. Like ->greeting('Dear User' . $this->user->name)

The following didn't work as well:

Notification::send($subscriber, new NotifySubscriber($post, $subscriber));

What should I do?

  • 写回答

1条回答 默认 最新

  • duanguangsong2380 2018-11-23 03:10
    关注

    First make sure you use use Notifiable; inside your Subscribe model.

    then you can access $notifiable it's an instance of the collection you send to the notification class.

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $url = url('/invoice/'.$this->invoice->id);
    
        return (new MailMessage)
                    ->greeting('Hello!'. $notifiable->user->name)
                    ->line('One of your invoices has been paid!')
                    ->action('View Invoice', $url)
                    ->line('Thank you for using our application!');
    }
    

    Check this link more details.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀