Hello guys hope you can help me and gimme some advice cause i don't know what to do right now. Please kindly help.
I've dynamic form where i can add (append) new row but when i tried to save it's value in DB is filled by NULL. Please look into my code
This is my View
<tbody>
<tr>
<td>1</td>
<td><textarea class="form-control" rows="3" name="analisa1" placeholder="Analisa Penyebab" style="resize: none;
height: 50px"></textarea></td>
<td><textarea class="form-control" rows="3" name="tindakan1" placeholder="Tindakan Perbaikan dan Pencegahan"
style="resize: none; height: 50px"></textarea></td>
<td><input class="form-control" type="text" name="pic1" placeholder="PIC"></td>
<td><input class="form-control" type="date" name="tanggal_pelaksanaan1"</td>
</tr>
</tbody>
</table>
<a class="button" href="#" role="button" id="add"> Tambah Analisa</a>
And this is my Javascript
$(document).ready(function(){
var i = 1;
$('#add').click(function(){
i++;
$('#tbanalisa tbody').append("<tr>"+"<td>"+i+"</td>"+"<td><textarea class=\"form-control\" rows=\"3\" name=\"analisa"+i+"\" placeholder=\"Analisa Penyebab\" style=\"resize: none; height: 50px\"></textarea></td>"+"<td><textarea class=\"form-control\" rows=\"3\" name=\"tindakan"+i+"\" placeholder=\"Tindakan Perbaikan dan Pencegahan\"style=\"resize: none; height: 50px\"></textarea></td>"+"<td><input class=\"form-control\" type=\"text\" name=\"pic"+i+"\" placeholder=\"PIC\"></td>"+"<td><input class=\"form-control\" type=\"date\" name=\"tanggal_pelaksanaan"+i+"\" id=\"date"+i+"\" ></td>"+"</tr>");
document.getElementById('count').value = i;
});
});
And this is my function in Controller
for($i=1; $i<=2; $i++){
$data[] = array(
'id_tindakan'=>$tindakan->id,
'analisa'=>$request->analisa[$i],
'tindakan'=>$request->tindakan[$i],
'pic'=>$request->pic[$i],
'tanggal_pelaksanaan'=>$request->tanggal_pelaksanaan[$i]
);
}
DB::table('analisas')->insert($data);
via Christianus Andre