【发布时间】:2018-10-09 08:17:05
【问题描述】:
我编写了一个与使用 Notifiable 特征的数据库没有任何关系的自定义模型。为了支持数据库通知,我在此类中添加了 routeNotificationForDatabase() 方法,如下所示:
public function routeNotificationForDatabase()
{
return new Notification();
}
但是,这会导致以下错误。所以很明显我做错了什么。有人能指出我正确的方向吗?
Illuminate\Database\QueryException:数组到字符串的转换(SQL:插入
notifications(id,type,data,read_at,updated_at,created_at)值(783ee870- cd52-4a2e-bdeb-fd89ca2aee11, App\Notifications\SystemMessage, 警告! example.com 目前已关闭。, , 2018-04-28 18:53:35, 2018-04-28 18: 53:35))
堆栈跟踪:
1 ErrorException::("数组到字符串的转换") /Users/xxx/sites/xxx/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:101
2 PDOStatement::bindValue(["警告! example.com 当前已关闭。"]) /Users/xxx/sites/xxx/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:101
提前谢谢你。
编辑:通过使用toSpark() 通知渠道而不是toDatabase() 解决了这个问题。我没有意识到 spark 的通知模型略有不同。
【问题讨论】:
-
你正在尝试调用 vendor\laravel\framework\src\Illuminate\Notifications\Notification.php 方法?
-
@outman 感谢您的回复。我发现 spark 在他们的通知模型中的设置略有不同。因此,我现在没有使用
toDatabase(),而是转向toSpark(),这正是我所需要的。
标签: laravel eloquent laravel-spark