【发布时间】:2020-09-21 01:46:31
【问题描述】:
我使用 Laravel 并尝试将条目添加到 JSON 格式的 MySQL 字段...
此字段包含(例如)以下内容:
{
"df2jay22p1f1nb31b161jf2jay22p5":
{
"type": "texte-image",
"contenu": "Texte de test",
"position": "2"
},
"df2jay1w251p1nb31a2f24f2jay1w256":
{
"type": "contenu-seul",
"contenu": "Contenu de test",
"position": "1"
}
}
我的目标是:
{
"df2jay22p1f1nb31b161jf2jay22p5":
{
"type": "texte-image",
"contenu": "Texte de test",
"position": "2",
"image": "/url/to/img.jpg"
},
"df2jay1w251p1nb31a2f24f2jay1w256":
{
"type": "contenu-seul",
"contenu": "Contenu de test",
"position": "1"
}
}
我的控制器是这样工作的:
$page = new Page();
$page->contenu = $request->input('composants'); // Json field
$page->save();
foreach($page->contenu as $i => $element){
if ( $request->hasFile("composants." . $i . ".image") ){
$image = $request->file("composants." . $i . ".image");
// ... image processing, save on directory, etc...
}
}
因此我想接手
的内容$page->contenu
并为其添加“图像”的值,但我无法实现...
提前谢谢你:)
【问题讨论】:
-
阅读JSON_SET()上的文档