我尝试在我的 channel 上发送一个简单的 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.
最佳答案
Composer 没有更新...
这是我找到的解决方案!
composer require laravel/slack-notification-channel
关于php - 尝试使用 Laravel 5.8 向我的 slack 发送通知时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58451147/