我已经使用jquery取得了复制的形式输入,如何插入的所有数据
<tbody id="visites">
<tr id="ligne">
<td> <input type... name="id[]"></td>
<td> <input type... name="date[]"></td>
<td> <input type... name="statut[]"></td>
</tr>
</tbody>
<script type="text/javascript">
function dupliquer()
{
$( "#ligne" ).clone().appendTo( "#visites" );
}
</script>
这是请求包
id
0 "1"
1 "1"
2 "1"
3 "1"
date
0 null
1 null
2 null
3 null
statut
0 null
1 null
2 null
3 null
该模型可填写的是
['id','date','statut']
我想请求()包转换为类似的东西
$data = [
{id:1,date:'..',statut:'3'},
{id:1,date:'..',statut:'3'},
{id:1,date:'..',statut:'3'}
]
而执行此:
foreach($data as ....)
{
Model::create([...]);
}
Summarly这是请求包Request bag这就是我想要的Data我希望我心中已经是明确的^^感谢。
你可以尝试这样做
$dataArray = [];
foreach($request['id'] as $key => $value){
// create new empty object
$ob = new \stdClass;
$ob->id = $request['id'][$key];
$ob->date = $request['date'][$key];
$ob->status = $request['statut'][$key];
// push the new object to the array
$dataArray[] = $ob;
}