请问当字段是多属性数组的时候,页面应该如何写
1. 运行环境
1). 当前使用的 Laravel 版本?
Laravel: 8.83.29
2). 当前使用的 php/php-fpm 版本?
PHP 版本:7.4
3). 当前系统
windows10
2. 问题描述?
我从后台数据库拿到的数据是一个json字段。字段中存了3个集合对象。我现在需要对这个数据进行修改,但是表单页面好像无法绑定
$form->embeds('animal', '动物信息', function ($form) {
$form->array('identifiable', '可识别鸟类', function ($identifiable){
$identifiable->text('type', '动物类型')->required();
$identifiable->text('number', '动物数量')->rules('integer|min:1|max:9999')->required();
$identifiable->multipleImage('images', '动物图片')->autoUpload()->uniqueName()->saving(function ($images) {
$fullPaths = [];
foreach ($images as $image){
$fullPaths[] = $image ;
}
return json_encode($fullPaths);
})->limit(5);
$identifiable->text('note', '备注');
})->saveAsJson();
$form->array('unidentification', '未识别鸟类', function ($unidentification){
$unidentification->text('type', '动物类型')->required();
$unidentification->text('number', '动物数量')->rules('integer|min:1|max:9999')->required();
$unidentification->multipleImage('images', '动物图片')->autoUpload()->saving(function ($images) {
$fullPaths = [];
foreach ($images as $image){
$fullPaths[] = $image ;
}
return json_encode($fullPaths);
})->limit(5);
$unidentification->text('note', '备注');
})->saveAsJson();
$form->array('other', '其他动物', function ($other){
$other->text('type', '动物类型')->required();
$other->text('number', '动物数量')->rules('integer|min:1|max:9999')->required();
$other->multipleImage('images', '动物图片')->autoUpload()->saving(function ($images) {
$fullPaths = [];
foreach ($images as $image){
$fullPaths[] = $image ;
}
return json_encode($fullPaths);
})->limit(5);
$other->text('note', '备注');
})->saveAsJson();
});
json格式应该是这样的
"animal": {
"identifiable": [
{
"type": "猫头鹰",
"number": 2,
"images": [],
"note": "备注"
}
],
"unidentification": [
{
"type": "猫头鹰",
"number": 2,
"note": "备注"
}
],
"other": [
{
"type": "猫头鹰",
"number": 2,
"note": "备注"
}
]
},
这样写虽然能正常展示,但是不能正常修改。文档中看到的$form->embeds和 $form->array好像不能嵌套使用。提交表单的时候form是直接有了identifiable 和unidentification和other这三个参数。且上传图片的时候id并非这个表单的id,导致不能上传成功
3. 您期望得到的结果?
请问如果要实现这种问题。我页面应该如何写
//: <> (能截图就截图。)