Exemplo n.º 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]);
 }
Exemplo n.º 2
0
 public function deleteIndonesianId($id, $thid)
 {
     //hapus di table terhah
     //$indonesian = Indonesian::find($id);
     //$indonesian->delete();
     //end
     //hapus di table thtoina
     $th_to_ina = ThtoId::where('indonesian_id', $id)->where('terhah_id', $thid)->delete();
     //end
     //return 'kata terhah sudah di hapus';
     return back()->withInput();
 }