0
votes

I'm trying to assign the many data in one form, but it gives me this error although there is data in id_personalia.

Here is the error message:

SQLSTATE[HY000]: General error: 1364 Field 'id_personalia' doesn't have a default value (SQL: insert into `tbl_personalia_perusahaan` (`id_profil_penyedia`, `nm_personal`, `tgl_personal`, `pendidikan_personal`, `jbtn_personal`, `pengalaman_personal`, `keahlian_personal`, `sertif_personal`, `path_personal`) values (9, Bambang, 24 ns, sd, sekretaris, 3, ada, ada, archive_gambar/138/pendaftaran_perusahaan/138-personal-1.pdf))

and this the value enter image description here

My controller:

$nop = 1;

foreach ($request->nm_personal as $person=>$p) {
    $nmpersonal = $sesi . '-personal-' . $nop . '.' . $request->img_personal[$person]->getClientOriginalExtension();

    $path_personal = 'archive_gambar/' . $sesi . '/pendaftaran_perusahaan/' . $nmpersonal;

    $request->img_personal[$person]->move($tujuan_upload, $nmpersonal);

    $data7 = array(
        'id_profil_penyedia'  => $id_perus,
        'nm_personal'         => $request->nm_personal[$person],
        'tgl_personal'        => $request->tgl_personal[$person],
        'pendidikan_personal' => $request->pendidikan_personal[$person],
        'jbtn_personal'       => $request->jbtn_personal[$person],
        'pengalaman_personal' => $request->pengalaman_personal[$person],
        'keahlian_personal'   => $request->keahlian_personal[$person],
        'sertif_personal'     => $request->sertif_personal[$person],
        'path_personal'       => $path_personal
    );

    $nop++;

    ModelPersonalia::insert($data7);                
}
2
Note that strings need quoting. And assign the column a default value when creating your tableStrawberry
I don't see id_personalia field in your $data7 array. Try adding it there.Qumber
You should set a default value for id_personalia field, otherwise you should set a value for id_personalia field in $data7 array.Tushar
One thing you can do is to update the id_personalia field nullable Or Make a default value for the field.Jithesh Jose
id_personalia is primary key. and the primary key is auto generate right?Muqsith Arsyad

2 Answers

0
votes

Use one of this solutions depending on your app logic...

Solution 1:

In your database make id_personalia nullable or assign default value to it

Solution 2:

In your migration make id_personalia nullable or assign default value to it: $table->integer('id_personalia')->nullable()->default(0);

Solution 3:

In your controller assign value to id_personalia.

$data7 = array(
    'id_profil_penyedia'=>$id_perus,
    'nm_personal'=>$request->nm_personal[$person],
    'tgl_personal'=>$request->tgl_personal[$person],
    'pendidikan_personal'=>$request->pendidikan_personal[$person],
    'jbtn_personal'=>$request->jbtn_personal[$person],
    'pengalaman_personal'=>$request->pengalaman_personal[$person],
    'keahlian_personal'=>$request->keahlian_personal[$person],
    'sertif_personal'=>$request->sertif_personal[$person],
    'path_personal'=>$path_personal,
    // here
    'id_personalia'=>$request->id_personalia,
);

$nop++;

ModelPersonalia::insert($data7); 

Do not forget to add it ModelPersonalia's fillable property or make all guarded protected $guarded = [];

Hope this helps you

0
votes

It's most likely due to the fact id_personalia is not in the $fillable array in the model corresponding to the table.