【发布时间】:2020-05-18 12:13:30
【问题描述】:
我有一个动态表,可以在其中添加和删除行。在每一行中,都有一些输入,用户可以在其中向对象添加数据。
现在,我将每个索引号硬编码为名称 attr。像这样:
<input type="text" name="reports[0][title]">
<input type="text" name="reports[0][description]">
<input type="text" name="reports[1][title]">
<input type="text" name="reports[1][description]">
是否可以这样做:
<input type="text" name="reports[][title]">
<input type="text" name="reports[][description]">
<input type="text" name="reports[][title]">
<input type="text" name="reports[][description]">
并像在硬编码索引时一样接收请求?
我需要将多个对象发布到控制器中的 store 方法。当我收到请求时,我希望数据是这样的,而不需要对索引进行硬编码。
"reports": [
{
"title": "Title 1",
"description": "Description 1"
},
{
"title": "Title 2",
"description": "Description 2"
}
]
提前致谢。
【问题讨论】:
标签: html arrays laravel forms laravel-blade