[英]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.我尝试在我的频道上发送一个简单的 slack 通知,以了解客户何时购买或注册,但我遇到了一个错误,我在 web 上找不到任何解决方案。
That's my notification SlackNotification.php:这是我的通知 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)我还像文档要求的那样更新 User.php (当然是我的个人代码)
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.
The composer was not update... Here the solution i've found !作曲家没有更新......这是我找到的解决方案!
composer require laravel/slack-notification-channel
In my case, I had a Homestead VM with only 2048 MB RAM.就我而言,我有一个只有 2048 MB RAM 的 Homestead VM。 When I ran
composer require laravel/slack-notification-channel
first time, it failed due to lack of memory, but suddenly it managed to install the package, but this above-mentioned error persisted after testing.当我第一次运行
composer require laravel/slack-notification-channel
时,由于缺少 memory 而失败,但突然它设法安装了 package,但上述错误在测试后仍然存在。
Then I had to turn off my VM, temporarily upgrade its RAM to 4096 MB, edit Homestead.yaml
to recognize these same 4096 MB, then I turned it on again, and once I was connected via SSH I ran composer require laravel/slack-notification-channel
again, then composer dumpautoload
and composer install
.然后我不得不关闭我的虚拟机,暂时将其 RAM 升级到 4096 MB,编辑
Homestead.yaml
以识别这些相同的 4096 MB,然后我再次打开它,一旦我通过 SSH 连接我运行composer require laravel/slack-notification-channel
再次composer require laravel/slack-notification-channel
,然后composer dumpautoload
和composer install
。 As my machine has limited resources, I had to restart it with 2048 MB again, after reverting all this changes related to the temporary RAM upgrade.由于我的机器资源有限,在恢复所有与临时 RAM 升级相关的更改后,我不得不再次以 2048 MB 重新启动它。
Once it was up, I tested and then it worked perfectly.启动后,我进行了测试,然后它运行良好。 I believe the package wasn't well installed, or it was corrupted, or something like that.
我相信 package 没有安装好,或者它已经损坏,或者类似的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.