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.