【发布时间】:2020-11-20 13:28:56
【问题描述】:
我在使用 Slack 和 Nexmo 时遇到问题。
两者都在 via 函数中指定,但似乎在触发时,Laravel 没有命中 toSlack 或 toNexmo 函数,或 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,我需要将其添加到我的用户模型中。谢谢你的帮助:)
【问题讨论】:
-
在您的
toSlack方法中,在 return 语句之前有一个exit;调用。这可能就是原因。
标签: laravel laravel-8 laravel-notification