This is my code with form to create entries...
<tr id="trow" class="">
<td><input type="text" name="title[]" id=""></td>
<td><input type="text" name="role[]" id=""></td>
<td><input type="text" name="email[]" id=""></td>
<td><input type="text" name="phone[]" id=""></td>
<td><button type="button" class="btn btn-danger" onclick="btnDel(this)">x</button></td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-12">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
The logic inside the controller is:
public function bulkcreate(Request $request, Worker $worker){
$title = $request->title;
$role = $request->role;
$email = $request->email;
$phone = $request->phone;
for($i=0;$i<count($title);$i++){
$datasave = [
'title'=>$title[$i],
'role'=>$role[$i],
'email'=>$email[$i],
'phone'=>$phone[$i],
"created_at" => \Carbon\Carbon::now(),
"updated_at" => \Carbon\Carbon::now()
// "created_at" => date('Y-m-d H:i:s')
];
DB::table('workers')->insert($datasave);
}
return redirect('/workers')->with('message','Data input success');
}
The code has done the job for me. I am seeking something more practical and compact to complete this job. I was advised to put in some code to get assisted in an efficient way so I did this here.
I am looking forward to seeing your help.