【问题标题】:How to set the value of a jsonb field with key in dot notation?如何使用点符号中的键设置 jsonb 字段的值?
【发布时间】:2021-06-26 16:26:26
【问题描述】:

当我这样做时:

$user = User::find(123);
Illuminate\Support\Arr::set($user, 'foo.bar', 100);

我明白了:

PHP 注意:在 /Users/me/my-project/vendor/laravel/framework/src/Illuminate/Collections/Arr.php 第 575 行中,间接修改 User 的重载元素无效

[
  "bar" => 100,
]

并且$user中的值没有改变。

【问题讨论】:

  • 不确定您要做什么。但是假设json已经是一个对象,你试过$user->foo->bar = 100吗?

标签: laravel


【解决方案1】:

使用此代码

$user = User::find(123);
$user->update([
    'foo->bar' => 150
]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2020-04-09
    • 2017-01-06
    • 2022-10-19
    • 2012-04-20
    • 2023-02-01
    相关资源
    最近更新 更多