Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to send a notification to my slack with Laravel 5.8

I try to send a simple slack notification on my channel to know when a customer buy something or register but i've got an error and i can't find any solution on the web.

That's my notification 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 [
            //
        ];
    }
}

I also put update User.php like the documentation asked (with my personnal code of course)

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

Then when a customer buy something on my website

$user->notify(new SlackNotification);

All the use are correct.

Even if I am making the notification with the facade like this

\Notification::route('slack', env('SLACK_HOOK'))->notify(new SlackNotification());

I've got this result every time :

InvalidArgumentException Driver [slack] not supported.
like image 671
Maxime Brunet Avatar asked Oct 18 '19 12:10

Maxime Brunet


People also ask

Does slack use Laravel?

Slack is just one of many available Laravel notification packages.


1 Answers

The composer was not update... Here the solution i've found !

composer require laravel/slack-notification-channel
like image 186
Maxime Brunet Avatar answered Sep 22 '22 09:09

Maxime Brunet