Php 拉威尔一直在压平我的输入阵列
我试图在Laravel中一次为多个项目创建一个动态编辑表单。为此,我使用以下输入命名约定:Php 拉威尔一直在压平我的输入阵列,php,laravel,laravel-5,Php,Laravel,Laravel 5,我试图在Laravel中一次为多个项目创建一个动态编辑表单。为此,我使用以下输入命名约定: name="groups[][name]" 无论出于何种原因,尝试在Laravel中处理此表单总是导致“组”输入为平面数组。我用以下方法取回这一套: $request->input('groups'); and var_dump shows: array( 10 ) { [0] => array( 1 ) {
name="groups[][name]"
无论出于何种原因,尝试在Laravel中处理此表单总是导致“组”输入为平面数组。我用以下方法取回这一套:
$request->input('groups');
and var_dump shows:
array(
10
)
{
[0] => array(
1
)
{
["name"] => string(15) "Baseball Cardsf"
}
[1] => array(
1
)
{
["description"] => string(22) "Baseball Cards Section"
}
[2] => array(
1
)
{
["id"] => string(1) "6"
}
[3] => array(
1
)
{
["willDelete"] => string(5) "false"
}
[4] => array(
1
)
{
["hasUpdated"] => string(4) "true"
}
[5] => array(
1
)
{
["name"] => string(12) "Board Gamesf"
}
[6] => array(
1
)
{
["description"] => string(19) "Board Games Section"
}
[7] => array(
1
)
{
["id"] => string(1) "5"
}
[8] => array(
1
)
{
["willDelete"] => string(5) "false"
}
[9] => array(
1
)
{
["hasUpdated"] => string(4) "true"
}
}
这是我的格式错误,还是拉威尔特有的问题
更新
问题是格式问题。使用$loop->index填充空[]修复了此问题。是的,您在格式设置上有错误,每次您为输入命名
组[]
输入索引递增1,您必须这样命名输入:
1st item
name="groups[0][name]"
name="groups[0][description]"
2nd item
name="groups[1][name]"
name="groups[1][description]"
您可以添加迭代器或其他内容。您可以使用一个临时数组,将每个键(如
name
、description
等)设置到其中,最后将其分配给组
e、 g
我尝试使用$loop->index来实现这一点,效果非常好。谢谢
1st item
name="groups[0][name]"
name="groups[0][description]"
2nd item
name="groups[1][name]"
name="groups[1][description]"
foreach ($items as $key=>$item){
$t = array();
$t["name"] = $item["name"];
$t["description"]= $item["description"];
$groups[] = $t;
}