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();
         }
     }
 }
 /**
  * Return categories by type
  *
  * @param $type
  * @return mixed
  */
 public function getByType($type)
 {
     $categories = Category::where('type', 'LIKE', $type)->get();
     return $categories;
 }
 /**
  * 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;
 }
 /**
  * Return spec by type
  *
  * @param $type
  * @return mixed
  */
 public function getByType($type)
 {
     $category = Category::where('type', 'support')->where('name', $type);
     return Support::where('category_id', $category->id);
 }
 /**
  * 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;
 }