Laravel - Trying to access array offset on value of type null

public function store(Request $request)
{

        $siswa_id = $request->siswa_id;
        $mapel_id = $request->mapel_id;
        $uh1 = $request->uh1;
        $uh2 = $request->uh2;
        $pts_ganjil = $request->pts_ganjil;
        $uh3 = $request->uh3;

foreach($mapel_id as $key => $mapel)
        {
            $input['siswa_id'] = $siswa_id;
            $input['mapel_id'] = $mapel;
            $input['uh1'] = $uh1[$key];
            $input['uh2'] = $uh2[$key];
            $input['pts_ganjil'] = $pts_ganjil[$key];
            $input['uh3'] = $uh3[$key];

            Nilai::create($input);

       }
}

Bagaimana

Bagaimana agar tetap dapat store ke database meskipun variabel request nya null? Error nya terdapat di dalam looping dengan error sbb:

 Trying to access array offset on value of type null
avatar Mofumofu
@Mofumofu

3 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban