Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 8更新JSON列值_Php_Laravel - Fatal编程技术网

Php Laravel 8更新JSON列值

Php Laravel 8更新JSON列值,php,laravel,Php,Laravel,我正在尝试为所有用户更新json列类型的值,我在Tinker中运行的查询没有给出任何错误,它只返回0,列保持不变,我做错了什么 User::where('notification\u preferences')->update(['notification\u preferences'=>[ “域”=>[ “到期日”=>[ “邮件”=>正确, “数据库”=>true ] ] ]]) “我的行中的我的列”当前的值为 { "expiry_alerts": true }

我正在尝试为所有用户更新
json
列类型的值,我在Tinker中运行的查询没有给出任何错误,它只返回
0
,列保持不变,我做错了什么

User::where('notification\u preferences')->update(['notification\u preferences'=>[
“域”=>[
“到期日”=>[
“邮件”=>正确,
“数据库”=>true
]
]
]])
“我的行中的我的列”当前的值为

{
    "expiry_alerts": true
}

我认为问题在于where子句
User::where('notification\u preferences')
,如果您将其表示为sql
User::where('notification\u preferences')->toSql()
,您会注意到类似的情况


来自通知首选项为空的用户…
,可能这就是更新未执行的原因。

在我阅读了下面的评论后,我清楚地意识到,您对JSON列的where查询使用了错误的语法。您必须使用->运算符

有关更多信息,请参见 &

它应该是这样工作的:

User::where('notification_preferences->expiry-alerts',true)->update(['notification_preferences' => [
  'domains' => [
    'expiry' => [
      'mail' => true,
      'database' => true
    ]
  ]
]])

你的WHERE中似乎缺少第二个参数。用户::where('notification_preferences',***此处****)-?我不理解expiry_alerts注释,因为它根本不包括在查询中?我在这里删除了******,因为它不起作用,得到了一个错误。就不理解过期警报而言,没有其他内容可供查看,更新列值的范围与我的描述一致,仅此而已删除where语句中的条件不是解决方案。;-)您的问题应该是“我的条件有什么问题”,而不仅仅是删除条件并想知道为什么结果为零。我的
notification\u preferences
列的类型为
json
。我有3个用户,每个用户在该列中都有以下json
{“到期提醒”:true}
。我现在需要根据我的描述将其值更改为json,我已经尝试添加
User::where('notification_preferences',[“expiry_alerts”:true])->toSql()
这不起作用,还有
User::where('notification_preferences',[“expiry_alerts”=>true])->toSql()
。我遗漏了什么?这是JSON列的错误语法。请看我的回答,以了解正确的语法。此评论应已发布到原始问题中。那么就更容易理解这个问题;-)这对我有用!这是我在手册中找到的第一个例子。。我对拉威尔一无所知;-)