0

我在使用 Slack 和 Nexmo 时遇到问题。

两者都在 via 函数中指定,但似乎在触发时,Laravel 没有命中toSlackortoNexmo函数或routeNotificationForSlack函数。我试图退出或打印一些东西来证明它已经到了这一点,但都没有奏效。

我也尝试过清除缓存(使用 DDEV 作为本地环境)。

namespace App\Notifications;

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\NexmoMessage;
use Illuminate\Notifications\Messages\SlackMessage;


class PaymentReceived extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['nexmo' , 'mail' , 'database' , 'slack'];
    }

    /**
     * Get the Slack representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return SlackMessage
     */
    public function toSlack($notifiable)
    {
        exit;
        return (new SlackMessage)
            ->from('Ghost', ':ghost:')
            ->content('That was some good food.');
    }

    /**
     * Route notifications for the Slack channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForSlack($notification)
    {

        return 'MY_HOOK_HERE';
    }
}

任何帮助,将不胜感激。

更新

感谢下面的@patricus,我需要在我的用户模型上添加它。谢谢您的帮助 :)

4

1 回答 1

0

routeNotificationForSlack()方法属于通知对象,而不是通知。

如果可通知对象没有定义此方法,则松弛通知通道将永远不会真正调用该toSlack()方法。

将您的routeNotificationForSlack()方法移动到通知对象,您应该会看到您的toSlack()方法开始被调用。

于 2020-11-20T13:44:08.297 回答