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

Jea*_*tre 5 php slack-api laravel-notification laravel-5.8

我尝试在我的频道上发送一个简单的 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 [
            //
        ];
    }
}

Run Code Online (Sandbox Code Playgroud)

我也像要求的文档一样更新 User.php(当然还有我的个人代码)

public function routeNotificationForSlack($notification)
{
    return 'https://hooks.slack.com/services/XXXXXXXXXXXX';
}
Run Code Online (Sandbox Code Playgroud)

然后当客户在我的网站上购买东西时

$user->notify(new SlackNotification);
Run Code Online (Sandbox Code Playgroud)

所有的使用都是正确的。

即使我用这样的外观制作通知

\Notification::route('slack', env('SLACK_HOOK'))->notify(new SlackNotification());
Run Code Online (Sandbox Code Playgroud)

我每次都得到这个结果:

InvalidArgumentException Driver [slack] not supported.
Run Code Online (Sandbox Code Playgroud)

Jea*_*tre 8

作曲家没有更新......这是我找到的解决方案!

composer require laravel/slack-notification-channel
Run Code Online (Sandbox Code Playgroud)