为什么 routeNotificationForNexmo 没有效果?

Why is routeNotificationForNexmo having no effect?

我有通过 Nexmo 发送的短信通知。他们正在工作,但我已经更改了设置收件人 phone 号码的方式,并且需要使用 routeNotificationForNexmo 方法覆盖默认值。

但是,似乎无论我用那个方法做什么,应用程序都会忽略它并且没有任何改变。我可以更改此文件中的其他内容,例如 SMS 消息内容,并查看从 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)。我试过停止并重新启动所有容器。

已解决。不确定我是从哪里想到将 routeNotificationForNexmo() 函数放在通知中的 class。它属于用户 class、User.php 文件。