我尝试在我的频道上发送一个简单的 slack 通知,以了解客户何时购买或注册,但我遇到了错误,我在网络上找不到任何解决方案。
这是我的通知 SlackNotification.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\SlackMessage;
class SlackNotification 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 ['slack'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\SlackMessage
*/
public function toSlack($notifiable)
{
return (new SlackMessage)
->from('Ghost', ':ghost:')
->to('#new-user-notification')
->content('Hello World !');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
我还按照文档要求更新 User.php (当然是我的个人代码)
public function routeNotificationForSlack($notification)
{
return 'https://hooks.slack.com/services/XXXXXXXXXXXX';
}
然后当客户在我的网站上购买东西时
$user->notify(new SlackNotification);
所有的使用都是正确的。
即使我用这样的外观发出通知
\Notification::route('slack', env('SLACK_HOOK'))->notify(new SlackNotification());
我每次都得到这个结果:
InvalidArgumentException Driver [slack] not supported.