I want to insert dynamic fields into DB. I'm using the following code but it does not work as I expect.
<html>
<input id="reporting" type="text" value="salman" name="reporting[]">
<input id="reporting" type="text" value="ankur" name="reporting[]">
</html>
<?php
$report = Input::get('reporting');
for($i=0; $i<=count($report);$i++)
{
$news = new Reporting();
$news->user_id = 1;
$news->reporting = $report;
$news->save();
}
?>
expected result:
user_id || reporting
1 Salman
1 Ankur
Can you guys please help me to fix this.
You could map the collection and create a new report while storing value of reports the way you want:
Catch data on backend:
This will produce the data in this format:
Note: Tested working correctly!
As
$report
is an array, current item of it can be received with[]
notation: