我在使用 Slack 和 Nexmo 时遇到问题。
两者都在 via 函数中指定,但似乎在触发时,Laravel 没有命中toSlack
ortoNexmo
函数或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,我需要在我的用户模型上添加它。谢谢您的帮助 :)