php - Laravel 8 更新 JSON 列值
问题描述
我正在尝试为json
我的所有用户更新列类型的值,我通过 Tinker 运行的查询没有给出任何错误,它只是返回0
并且列保持不变,我做错了什么?
User::where('notification_preferences')->update(['notification_preferences' => [
'domains' => [
'expiry' => [
'mail' => true,
'database' => true
]
]
]])
我的行上的列当前具有...的值
{
"expiry_alerts": true
}
解决方案
在我阅读了下面的评论之后,我很清楚您对 JSON 列的 WHERE 查询使用了错误的语法。您必须使用 ->运算符。
有关详细信息,请参阅https://mattstauffer.com/blog/new-json-column-where-and-update-syntax-in-laravel-5-3/ 和 https://laravel.com/docs/8。 x/查询#json-where-clauses
它应该像这样工作:
User::where('notification_preferences->expiry-alerts',true)->update(['notification_preferences' => [
'domains' => [
'expiry' => [
'mail' => true,
'database' => true
]
]
]])
推荐阅读
- node.js - 如果与 express 有共享会话,是否需要验证 socket.io 连接?
- jvm-arguments - 如何使用 inlinedConfScript 配置 JAVA_OPTS 和 maven?
- matplotlib - ImportError:无法导入名称'_path'
- java - Spring boot 配置和配置属性的问题
- c# - 如何使用 .net-core 中的 IDirectoryContents 循环 wwwroot 文件?
- python - 在仅部分匹配的列上合并 DataFrame
- python - 比较python中的两个列表并在某些条件下检查它们是否相等
- delphi - 如果 CheckBox 已更改,如何使用 CheckBoxes 在 FMX.TreeView 中获取项目索引?
- android - 改造,发送带图像的多部分正文
- javascript - Windows.location.assign 在 js 函数中不起作用