i have made a duplicable form input using jquery, how do i insert all data
<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>
This is the request bag
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
The model fillable are
['id','date','statut']
I want to transform the request() bag to something like that
$data = [
{id:1,date:'..',statut:'3'},
{id:1,date:'..',statut:'3'},
{id:1,date:'..',statut:'3'}
]
and perform this :
foreach($data as ....)
{
Model::create([...]);
}
Summarly this is the request bag Request bag And this is what i want Data I hope i'v been clear ^^ thanks.
you can try doing this
$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;
}