public function name($lang_iso = null) { if ($lang_iso == null) { $lang_iso = \App::getLocale(); } $lang = Lang::whereIso($lang_iso)->first(); return Translation::where('lang_id', $lang->id)->where('table', $this->table)->where('table_id', $this->id)->first()->value; }
public function run() { $categories = [['product', ['pt' => 'rodas', 'en' => 'wheels', 'es' => 'ruedas'], 0], ['product', ['pt' => 'estrada', 'en' => 'road', 'es' => 'carretera'], 1], ['news', ['pt' => 'geral', 'en' => 'main', 'es' => 'general'], 0], ['spec', ['pt' => 'tecnologias', 'en' => 'technologies', 'es' => 'tecnologias'], 0]]; foreach ($categories as $category) { $c = new Category(); $c->parent_id = $category[2]; $c->type = $category[0]; $c->save(); foreach ($category[1] as $lang => $value) { $lang_id = Lang::whereIso($lang)->first()->id; $t = new Translation(); $t->lang_id = $lang_id; $t->table = 'categories'; $t->table_id = $c->id; $t->value = $value; $t->save(); } } }
/** * Update Category * * @param $id * @param $names * @param $parent_id * @return mixed */ public function update($id, $names, $parent_id) { $category = Category::findOrFail($id); if ($category->parent_id != $parent_id) { $category->parent_id = $parent_id; } $aux = false; foreach ($names as $iso => $name) { $lang = Lang::whereIso($iso)->first(); $aux = $this->translationRepositoryInterface->update($lang->id, 'categories', $category->id, strtolower($name)); } return $aux ? $category->save() : false; }
/** * Update News * * @param $id * @param $title * @param $slug * @param $category * @param $content * @param $addFiles * @param $removeFiles * @return mixed */ public function update($id, $title, $slug, $category, $content, $addFiles, $removeFiles) { $category = Category::findOrFail($category); $news = News::findOrFail($id); try { $news->category_id = $category->id; $news->user_id = \Auth::user()->id; $news->slug = $slug; $news->save(); //cria as traduções foreach ($content as $iso => $value) { $lang = Lang::whereIso($iso)->first(); $this->translationRepositoryInterface->updateKeyValue($lang->id, 'news', $news->id, $value, $title[$iso]); } //adiciona novas imagens if (!is_null($addFiles)) { foreach ($addFiles as $file) { $this->mediaRepositoryInterface->updateTable($file, 'news', $news->id); } } if (!is_null($removeFiles)) { //remove imagens foreach ($removeFiles as $file_id) { $this->mediaRepositoryInterface->deleteById($file_id); } } } catch (\Exception $e) { \Log::error($e); return false; } return true; }
public function getTitleAttribute() { $lang = Lang::whereIso(\App::getLocale())->first(); return Translation::where('lang_id', $lang->id)->where('table', $this->table)->where('table_id', $this->id)->first()->key; }
/** * Update Spec * * @param $id * @param $category * @param $name * @param $descriptions * @param $addImage * @param $removeImage * @return mixed */ public function update($id, $category, $name, $descriptions, $addImage, $removeImage) { $category = Category::findOrFail($category); $spec = Spec::findOrFail($id); try { $spec->category_id = $category->id; $spec->name = strtolower($name); $spec->save(); //cria as traduções foreach ($descriptions as $iso => $value) { $lang = Lang::whereIso($iso)->first(); $this->translationRepositoryInterface->update($lang->id, 'specs', $spec->id, $value); } //adiciona novas imagens if (!empty($addImage)) { $this->mediaRepositoryInterface->updateTable($addImage, 'specs', $spec->id); } if (!empty($removeImage)) { $this->mediaRepositoryInterface->deleteById($removeImage); } } catch (\Exception $e) { \Log::error($e); return false; } return true; }