laravel - Laravel 中的 Slack 通知错误参数太少
问题描述
我正在尝试在我的 laravel 项目中实现松弛通知。
在我的控制器内部,我调用:
$user->notify(new WorkAdded());
这里的WorkAdded
类
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['slack'];
}
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
* @return SlackMessage
*/
public function toSlack($notifiable)
{
return (new SlackMessage)
->content('TEST');
}
在User
我添加的课程中:
use Notifiable;
public function routeNotificationForSlack($notification)
{
return 'https://hooks.slack.com/services/...';
}
但是当我调用通知函数时,出现以下错误:
类型错误:函数 App\User::routeNotificationForSlack() 的参数太少,在第 30 行的 /Applications/MAMP/htdocs/gest/vendor/laravel/framework/src/Illuminate/Notifications/RoutesNotifications.php 中传递了 0,正好是 1预期的
解决方案
如果您使用的是 Laravel 5.5 或更低版本,则routeNotificationFor{driver}
方法不会传递$notification
实例。
将您的方法更改为以下应该是您所需要的:
public function routeNotificationForSlack()
{
return 'https://hooks.slack.com/services/...';
}
使用 Laravel 文档时,最好将屏幕右上角的下拉菜单更改为您正在使用的 Laravel 版本。
推荐阅读
- python - IndexError:运行 mask-rcnn 时列表索引超出范围?
- android - InputManager 自动从列表中删除无线控制器
- python - 如何修复 [Errno 20] 不是目录:'/app/myProjectManager/settings.py/staticfiles/staticfiles.json' Django
- python - 在 y 轴上绘制多个日期时间列,在 x 轴上绘制它们对应的 id
- wordpress - 所有帖子的WordPress作者更改
- laravel - Laravel:如何使用户的所有会话从 redis 无效并从所有设备注销?
- javascript - 无法使用js将文件值发送到asp.net mvc中的控制器
- python - 短信散点图
- scala - 使用 Akka HTTP 和 circe 处理 PATCH 请求以获取可空字段
- gradle - 使用IDEA时如何修复build.gradle的`import com.r3.testing.DistributeTestsBy`的红色警告?