コード例 #1
0
 /**
  *
  */
 public function run()
 {
     $langs = [['portuguese', 'pt'], ['english', 'en'], ['spanish', 'es']];
     foreach ($langs as $lang) {
         $a = new Lang();
         $a->name = $lang[0];
         $a->iso = $lang[1];
         $a->setCreatedAt(\Carbon\Carbon::now());
         $a->setUpdatedAt(\Carbon\Carbon::now());
         $a->save();
     }
 }
コード例 #2
0
 public function attributes()
 {
     $attributes = ['imagesList' => ' Imagem'];
     foreach (Lang::all() as $lang) {
         $attributes['description.' . $lang->iso] = "Descrição em " . trans("home.{$lang->name}");
     }
     return $attributes;
 }
コード例 #3
0
 public function messages()
 {
     $messages = [];
     foreach (Lang::all() as $lang) {
         $messages['name.' . $lang->iso . '.required'] = 'O campo nome em ' . trans('home.' . $lang->name) . ' é obrigatório';
     }
     return $messages;
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 public function messages()
 {
     $messages = [['category.required' => 'O campo categoria é obrigatório'], ['slug.required' => 'O campo nome Slug é obrigatório'], ['slug.unique' => 'O campo nome Slug tem de ser único']];
     foreach (Lang::all() as $lang) {
         $messages['title.' . $lang->iso . '.required'] = 'O campo Titulo em ' . trans('home.' . $lang->name) . ' é obrigatório';
         $messages['content.' . $lang->iso . '.required'] = 'O campo Conteudo em ' . trans('home.' . $lang->name) . ' é obrigatório';
     }
     return $messages;
 }
コード例 #6
0
 /**
  *
  */
 public function getLangs()
 {
     $langs = Lang::all();
     //        dd($langs);
     $return = array();
     foreach ($langs as $lang) {
         $return[] = array('id' => "{$lang->id}", 'iso' => "{$lang->iso}", 'name' => trans("home.{$lang->name}"));
     }
     return json_encode($return);
 }
コード例 #7
0
 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();
         }
     }
 }
コード例 #8
0
 /**
  * Update Spec
  *
  * @param $id
  * @param $category
  * @param $name
  * @param $lang
  * @param $file
  * @return mixed
  */
 public function update($id, $category, $name, $lang, $file)
 {
     $category = Category::findOrFail($category);
     $lang = Lang::findOrFail($lang);
     $support = Support::findOrFail($id);
     try {
         $support->category_id = $category->id;
         $support->name = strtolower($name);
         $support->lang_id = $lang->id;
         $support->save();
         if (!is_null($file)) {
             $this->mediaRepositoryInterface->deleteByTable('supports', $id);
             $this->mediaRepositoryInterface->create($file, 'supports', $support->id);
         }
     } catch (\Exception $e) {
         \Log::error($e);
         if (!is_null($support) && $support->exists) {
             $this->delete($support->id);
         }
         return false;
     }
     return true;
 }
コード例 #9
0
 /**
  * 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;
 }
コード例 #10
0
 /**
  * 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;
 }
コード例 #11
0
ファイル: News.php プロジェクト: jonioliveira/prototype2015
 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;
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->share('langs', Lang::all());
 }