/**
  * 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;
 }
 /**
  * Return category by Id
  *
  * @param $id
  * @return mixed
  */
 public function getById($id)
 {
     return Category::findOrFail($id);
 }
예제 #3
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;
 }
예제 #4
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;
 }