【问题标题】:Laravel notification class not pass variableLaravel 通知类不传递变量
【发布时间】:2018-09-10 09:50:36
【问题描述】:

我无法将sendSms 传递给toHistory 方法。它始终设置为false。我怎样才能正确地做到这一点?

class SendMessage extends Notification implements ShouldQueue
{
    use Queueable;
    public $sendSms;

    public function via($notifiable)
    {
        $this->sendSms = true;
    }

    public function toHistory($notifiable) {
        echo $this->sendSms; //return false
    }
}

【问题讨论】:

    标签: laravel laravel-5 laravel-notification


    【解决方案1】:

    查看official Laravel Notifications doc's,似乎在覆盖via($notifiable) 方法时,您应该返回一个可以发送通知的通道数组。所以你可能想返回['nexmo'],假设nexmo是你想要使用的短信服务。

    【讨论】:

    • 是的,我返回 nexmo:return array_merge($this->sendSms ? ['nexmo'] : ['mail'], HistoryChannel::class]);(在我的帖子中我只添加了一部分代码)但 sendSmsvia() 中设置为 TRUE 松散值并且在 toHistory() 中具有 FALSE 值.我不知道为什么。 @alexkb
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 2014-12-11
    • 2012-05-26
    • 2021-07-08
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    相关资源
    最近更新 更多