public function parentName() { $categoryLanguages = \App\CategoryLanguage::where('locale', \Lang::getLocale())->where('category_id', $this->parent_id)->first(); if (!$categoryLanguages) { $categoryLanguages = \App\CategoryLanguage::where('locale', 'en')->where('category_id', $this->parent_id)->first(); } return $categoryLanguages ? $categoryLanguages->title : '-'; }
public function storeTranslate(Request $request) { DB::beginTransaction(); foreach ($request->title as $key => $title) { $categoryLang = \App\CategoryLanguage::where('category_id', $request->edit_translate)->where('locale', $key)->first(); if ($categoryLang) { $categoryLang->title = $title ? $title : ''; $categoryLang->description = $request->description[$key] ? $request->description[$key] : ''; $categoryLang->save(); } else { $categoryLang = new \App\CategoryLanguage(); if ($title) { $categoryLang->title = $title; } if ($request->description[$key]) { $categoryLang->description = $request->description[$key]; } if ($title || $request->description[$key]) { $categoryLang->locale = $key; $categoryLang->category_id = $request->edit_translate; $categoryLang->save(); } } } DB::commit(); return response()->json(array('status' => 200, 'monolog' => array('title' => 'update translation success', 'message' => 'Translation has been updated'))); }