gpt4 book ai didi

php - Laravel Eloquent 不更新 JSON 列 : Array to string conversion

转载 作者:可可西里 更新时间:2023-11-01 07:05:02 27 4
gpt4 key购买 nike

我想更新数据库中的 JSON 列,但出现此错误:

Array to string conversion  

我已在模型中将列名称声明为 array:

protected $casts = [
'destinations' => 'array'
];

这是我使用的代码:

$data[] = [
'from' => $fromArray,
'to' => $toArray
];

Flight::where('id', $id)->update(['destinations' => $data]);

我该怎么办?

最佳答案

您可以使用箭头访问您的 json 键,这样您就可以像这样更新您的列:

Flight::where('id', $id)->update([
'destinations->from' => $data['from'],
'destinations->to' => $data['to']
]);

As @fubar mentioned you have to have mysql 5.7 in order to have my solution to work.

检查docs

关于php - Laravel Eloquent 不更新 JSON 列 : Array to string conversion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45361861/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com