mardi 16 juillet 2019

cant save data on update method

i want to save data from avarage result of nilai tema table to nilai akhir table. but it show a error 'array_key_exists(): The first argument should be either a string or an integer'.

this is my update method

public function update(Request $request, $id)
    {
        $nilai = nilaiTema::find($id);
        $rataP = ($request->input('p_nilai1') + $request->input('p_nilai2') + $request->input('p_nilai3')) / 3;
        $rataK = ($request->input('k_nilai1') + $request->input('k_nilai2') + $request->input('k_nilai3')) / 3;
        $nilai->p_nilai1 = $request->input('p_nilai1');
        $nilai->p_nilai2 = $request->input('p_nilai2');
        $nilai->p_nilai3 = $request->input('p_nilai3');
        $nilai->p_rata = $rataP;
        $nilai->k_nilai1 = $request->input('k_nilai1');
        $nilai->k_nilai2 = $request->input('k_nilai2');
        $nilai->k_nilai3 = $request->input('k_nilai3');
        $nilai->k_rata = $rataK;
        $nilai->save();

        $nilaiRataPenalaran = DB::table('nilai_temas')
        ->where([
            ['idKelas','=',$nilai->idKelas],
            ['mataPelajaran','=','  Pendidikan Agama dan Budi Pekerti']
        ])
        ->avg('p_rata');
        $nilaiRataKetrampilan = DB::table('nilai_temas')
        ->where([
            ['idKelas','=',$nilai->idKelas],
            ['mataPelajaran','=','  Pendidikan Agama dan Budi Pekerti']
        ])
        ->avg('k_rata');

        $nilaiAkhir = nilaiUtsUas::all()
        ->where([
            ['idKelas','=',$nilai->idKelas],
            ['mataPelajaran','=',$nilai->mataPelajaran]
        ])-first();
        $nilaiAkhir->nilaiPenalaran=$nilaiRataPenalaran;
        $nilaiAkhir->nilaiKetrampilan=$nilaiRataKetrampilan;
        $nilaiAkhir->save();
        return redirect('/daftarSiswa')->with('success', 'jadwal telah di rubah!');

    }

my model is empty because the relationship is in mySql database, and im sure the problem is not come from the relationship.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire