Laravel 8通知-toSlack或toNexmo函数未触发

Laravel 8通知-toSlack或toNexmo函数未触发,laravel,laravel-8,laravel-notification,Laravel,Laravel 8,Laravel Notification,我对Slack和Nexmo有意见 这两个都在via函数中指定,但在触发时,Laravel似乎没有点击toSlack或toNexmo函数或routeNotificationForSlack函数。我试图退出或打印一些东西,以证明它已经达到了这一点,但都没有工作 我还尝试过清除缓存(使用DDEV作为本地环境) 任何帮助都将不胜感激 更新 多亏了下面的@patricus,我需要在我的用户模型上添加这个。感谢您的帮助:)方法属于应通知对象,而不是通知 如果notifiable对象没有定义此方法,slack

我对Slack和Nexmo有意见

这两个都在via函数中指定,但在触发时,Laravel似乎没有点击
toSlack
toNexmo
函数或
routeNotificationForSlack
函数。我试图退出或打印一些东西,以证明它已经达到了这一点,但都没有工作

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

任何帮助都将不胜感激

更新


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

方法属于应通知对象,而不是通知

如果notifiable对象没有定义此方法,slack通知通道将永远不会实际调用
toSlack()
方法


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

在您的
toSlack
方法中,有一个
出口调用,就在return语句之前。这可能就是原因。
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';
    }
}