【发布时间】:2018-01-03 20:04:59
【问题描述】:
我想更新我数据库中的 JSON 列,但我收到此错误:
Array to string conversion
我已在模型中将列名声明为array:
protected $casts = [
'destinations' => 'array'
];
这是我使用的代码:
$data[] = [
'from' => $fromArray,
'to' => $toArray
];
Flight::where('id', $id)->update(['destinations' => $data]);
我该怎么办?
【问题讨论】:
-
试试这个:
$flight = Flight::find($id); $flight->destinations = $data; $flight->save();见here -
@Maraboc 请发布您的答案
-
我刚刚意识到需要在问题中添加 laravel 版本标签。我需要在我的 laravel 项目中进行更新,但我不知道这个问题针对的是哪个版本。
标签: php mysql json laravel eloquent