为什么routeNotificationForNexmo没有效果?

时间:2018-04-15 07:24:55

标签: laravel-5.3

我收到通过Nexmo发送的短信通知。它们正在运行,但我已经改变了设置收件人电话号码的方式,并且需要使用routeNotificationForNexmo方法覆盖默认值。

然而,似乎无论我使用该方法做什么,应用程序都会忽略它并且没有任何变化。我可以更改此文件中的其他内容,例如短信内容,并查看Nexmo发送的新邮件中的更改。

为什么routeNotificationForNexmo无法正常工作?还有什么可以覆盖这个吗?

这是我的整个/Notifications/TeamMessage.php文件:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\NexmoMessage;

class TeamMessage extends Notification implements ShouldQueue
{
    use Queueable;

    protected $custom_message;
    protected $short_code;
    protected $reply_to;
    protected $reply_to_name;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($custom_message, $short_code, $channels, $reply_to, $reply_to_name)
    {
        $this->custom_message = $custom_message;
        $this->short_code = $short_code;
        $this->channels = $channels;
        $this->reply_to = $reply_to;
        $this->reply_to_name = $reply_to_name;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return $this->channels; //
    }

    /**
     * Route notifications for the Nexmo channel.
     *
     * @return string
     */
    public function routeNotificationForNexmo()
    {
      $number = $this->phone_number_country . $this->phone_number;
      $number = preg_replace("/[^0-9]/","", $number);  //Strips all non-numbers
      return $number;
    }

    /*  Send SMS   */
    public function toNexmo($notifiable)
    {
        return (new NexmoMessage)
            ->from(00000000000)
            ->content($this->custom_message . " \n\n Unsubscribe at http://" . env('TL_DOMAIN') . '/s/' . $this->short_code );
    }
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->replyTo($this->reply_to, $this->reply_to_name)
            ->line($this->custom_message)
            ->line('--')
            ->line("To unsubscribe, go to http://" . env('TL_DOMAIN') . '/s/' . $this->short_code);
            //->action('Notification Action', 'https://laravel.com');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

我在Laravel 5.3上,通过Docker(Laradock)在本地运行。我试过停止并重新启动所有容器。

1 个答案:

答案 0 :(得分:0)

解决。不知道我在哪里想到将routeNotificationForNexmo()函数放在通知类中。它属于User类User.php文件。