php - 尝试使用 Laravel 5.8 向我的 slack 发送通知时出错

标签 php slack-api laravel-5.8 laravel-notification

我尝试在我的 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/

相关文章:

php - Nodejs 过滤输入

php - 从其他用户领域生成盐

node.js - 图像链接 URL 使用 slack rtm API 显示每个图像的两个副本

php - 如何使策略自动发现新的 Laravel 功能与我在不同文件夹中的模型一起使用?

laravel - 带有中间表的两个模型之间的关系

php - 如何为 php 启用 sqlite3?

php - 如果第一个查询没有返回结果,则使用第二个查询

markdown - Slack是否支持Markdown表?

rest - 从 Slack slash 命令调用 Jenkins

php - 如何在 Laravel 中使用组合框更改数据?