/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $form = $request->all();
     //Cari penilaian latihan
     $penilaianLatihan = PenilaianLatihan::find($form['id']);
     //Save and relation peserta to penilaian latihan
     $peserta = new Peserta($form);
     $peserta = $penilaianLatihan->peserta()->save($peserta);
     //Saving Jawapan Penilaian
     foreach ($form['senaraiPenilaian'] as $bahagianPenilaian) {
         foreach ($bahagianPenilaian['skop'] as $skopPenilaian) {
             //Create new jawapan penilaian peserta and relation to peserta
             $jawapanPenilaian = new JawapanPenilaianPeserta();
             $jawapanPenilaian->jawapan = (int) $skopPenilaian['jawapan'];
             $jawapanPenilaian = $peserta->jawapanPenilaianPeserta()->save($jawapanPenilaian);
             //Relation jawapan penilaian peserta to skop
             $skop = SkopPenilaianLatihan::find($skopPenilaian['id']);
             $jawapanPenilaian->skop()->associate($skop);
             $jawapanPenilaian->save();
         }
     }
     //Saving Jawapan Pencapaian
     foreach ($form['senaraiPencapaian'] as $bahagianPencapaian) {
         foreach ($bahagianPencapaian['skop'] as $skopPencapaian) {
             //Skop pencapaian
             $skop = SkopPencapaianLatihan::find($skopPencapaian['id']);
             //Create new jawapan pencapaian sebelum peserta and relation to peserta
             $jawapanPencapaianSebelum = new JawapanPencapaianSebelum();
             $jawapanPencapaianSebelum->jawapan = $skopPencapaian['jawapanSebelum'];
             $jawapanPencapaianSebelum = $peserta->jawapanPencapaianSebelum()->save($jawapanPencapaianSebelum);
             //Relation jawapan pencapaian sebelum peserta to skop
             $jawapanPencapaianSebelum->skop()->associate($skop);
             $jawapanPencapaianSebelum->save();
             //Create new jawapan pencapaian selepas peserta and relation to peserta
             $jawapanPencapaianSelepas = new JawapanPencapaianSelepas();
             $jawapanPencapaianSelepas->jawapan = $skopPencapaian['jawapanSelepas'];
             $jawapanPencapaianSelepas = $peserta->jawapanPencapaianSelepas()->save($jawapanPencapaianSelepas);
             //Relation jawapan pencapaian selepas peserta to skop
             $jawapanPencapaianSelepas->skop()->associate($skop);
             $jawapanPencapaianSelepas->save();
             //Relation jawapan pencapaian selepas peserta with jawapan pencapaian sebelum peserta
             $jawapanPencapaianSelepas->pencapaianSebelum()->associate($jawapanPencapaianSebelum);
             $jawapanPencapaianSelepas->save();
         }
     }
     return ['success' => true];
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $penilaian_peserta = PenilaianLatihan::find($id);
     $penilaian_peserta->delete();
     return ['success' => true];
 }