Beispiel #1
0
 public function getAllTerhah()
 {
     $terhahs = Terhah::orderBy('word', 'asc')->get();
     $indonesian = Indonesian::all();
     $english = English::all();
     $thid = ThtoId::all();
     $then = ThtoEn::all();
     //return $terhah;
     //$indonesian = Terhah::find(1)->indonesian;
     //$english = Terhah::find(2)->english;
     $word_in_english = DB::table('th_to_eng')->leftJoin('english', 'th_to_eng.english_id', '=', 'english.id')->select('english.id', 'th_to_eng.terhah_id', 'english.word')->get();
     $word_in_indonesian = DB::table('th_to_ina')->leftJoin('indonesians', 'th_to_ina.indonesian_id', '=', 'indonesians.id')->select('indonesians.id', 'th_to_ina.terhah_id', 'indonesians.word')->get();
     //return $word_in_indonesian;
     //return $word_in_english;
     $data = array();
     foreach ($terhahs as $key => $terhah) {
         //unset($terhah->english);
         $kata_english = array();
         foreach ($word_in_english as $key => $wie) {
             if ($wie->terhah_id == $terhah->id) {
                 $kata_english[] = $wie->word;
             } else {
                 unset($terhah->english);
             }
             $terhah->english = $kata_english;
         }
         $kata_indonesian = array();
         foreach ($word_in_indonesian as $key => $wii) {
             if ($wii->terhah_id == $terhah->id) {
                 $kata_indonesian[] = $wii->word;
             } else {
                 unset($terhah->indonesian);
             }
             $terhah->indonesian = $kata_indonesian;
         }
         //  echo $terhah;
         $data[] = $terhah;
     }
     return response()->json(['results' => $data]);
 }
Beispiel #2
0
 public function postEditTerhahId(Request $request, $id)
 {
     //return $request->english;
     //return $request->all();
     $terhah = Terhah::find($id);
     $terhah->word = $request->word;
     $terhah->spelling = $request->spelling;
     $terhah->save();
     // return $request->all();
     //update data dari kata indonesia yang sudah diimput sebelumnya
     foreach ($request->indonesian as $key => $indo) {
         //var_dump($key);
         $update = Indonesian::find($key);
         $update->word = $indo;
         $update->save();
     }
     //end
     //update data dari kata english yang sudah diimput sebelumnya
     foreach ($request->english as $key => $eng) {
         //var_dump($key);
         $update = English::find($key);
         $update->word = $eng;
         $update->save();
     }
     //end
     //tambah arti kata baru indonesian
     foreach ($request->indoFields as $key => $newIndo) {
         echo $newIndo;
         $check = Indonesian::where('word', $newIndo)->first();
         if ($check === null) {
             //echo 'kata tersebut belum ada';
             $addNewIndo = new Indonesian();
             $addNewIndo->word = $newIndo;
             $addNewIndo->save();
             $addNewThtoId = new ThtoId();
             $addNewThtoId->terhah_id = $id;
             $addNewThtoId->indonesian_id = $addNewIndo->id;
             $addNewThtoId->save();
         } elseif ($newIndo == '') {
             // echo 'kata itu sudah ada';
             //echo $addNewIndo->get() ;
             echo 'isinya kosong';
         } else {
             $existingData = Indonesian::where('word', '=', $newIndo)->first();
             $addNewThtoId = new ThtoId();
             $addNewThtoId->terhah_id = $id;
             $addNewThtoId->indonesian_id = $existingData->id;
             $addNewThtoId->save();
             var_dump($existingData->id);
         }
     }
     //end
     //tambah arti kata baru english
     foreach ($request->engFields as $key => $newEng) {
         //            echo $newIndo;
         $check = English::where('word', $newEng)->first();
         if ($check === null) {
             echo 'kata tersebut belum ada';
             $addNewIndo = new English();
             $addNewIndo->word = $newEng;
             $addNewIndo->save();
             $addNewThtoId = new ThtoEn();
             $addNewThtoId->terhah_id = $id;
             $addNewThtoId->english_id = $addNewIndo->id;
             $addNewThtoId->save();
         } elseif ($newEng == '') {
             echo 'isinya kosong';
         } else {
             echo 'inggris kata itu sudah ada';
             //echo $addNewIndo->get() ;
             $existingData = English::where('word', '=', $newEng)->first();
             $addNewThtoId = new ThtoEn();
             $addNewThtoId->terhah_id = $id;
             $addNewThtoId->english_id = $existingData->id;
             $addNewThtoId->save();
             var_dump($existingData->word);
         }
     }
     //end
     //$indo = Indonesian::find();
     //   return 'data updated';
     return back()->withInput();
 }