0

I can't pass sendSms to toHistory method. It is always set as false. How can I do it properly?

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
    }
}
pelcomppl
  • 575
  • 2
  • 6
  • 16

1 Answers1

1

Looking over the official Laravel Notifications doc's it appears that when overriding the via($notifiable) method, you're suppose to return an array of channels the Notification can be sent through. So you probably want to return ['nexmo'] assuming nexmo is the sms service you want to use.

alexkb
  • 3,216
  • 2
  • 30
  • 30
  • Yes, I return nexmo: `return array_merge($this->sendSms ? ['nexmo'] : ['mail'], HistoryChannel::class]);` (in my post I added only a part of code) but `sendSms` set in `via()` to TRUE loose value and in `toHistory()` has FALSE value. I don't know why. @alexkb – pelcomppl Sep 11 '18 at 06:27