lundi 30 décembre 2019

Here my code to insert multiple records in database on laravel. So, it doesn't work? anyone help me?

i want insert multiple records in table at once submit into database using eloquent laravel, so i have tried hardly.

my code on controller

 $x = $request->all();
 $datas = DataAnak::create($x)->id_anak;

            if($datas != 0) {
                foreach ($datas as $key => $value) {
                    $rows = array(
                        'nama' => $request->nama_anak[$key],
                        'jenis_kelamin' => $request->gender_anak[$key],
                        'tempat_tgl_lahir' => $request->tmt[$key],
                        'tgl_baptis' => $request->baptis_anak[$key],
                        'tgl_sidi' => $request->sidi_anak[$key]
                    );
                    DataAnak::insert($rows);
                }
            }

my code on blade page

 <tr>
         <td><input type="text" class="form-control" name="nama_anak[]"></td>
         <td><input type="text" class="form-control" name="gender_anak[]"></td>
         <td><input type="text" class="form-control" name="tmt[]"></td>
         <td><input type="text" class="form-control" name="baptis_anak[]"></td>
         <td><input type="text" class="form-control" name="sidi_anak[]"></td>
         <td class="text-center"><button type="button" class="btn btn-danger row-del"><i class="fas            fa-times"></i></button></td>
    </tr>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire