Example #1
0
 /**
  * Delete Category: Category & connections
  *
  */
 protected function deleteCategory($cid)
 {
     if (empty($cid)) {
         return false;
     }
     \Veer\Models\Category::destroy($cid);
     \Veer\Models\CategoryConnect::where('categories_id', '=', $cid)->forceDelete();
     \Veer\Models\CategoryPivot::where('parent_id', '=', $cid)->orWhere('child_id', '=', $cid)->forceDelete();
     \Veer\Models\ImageConnect::where('elements_id', '=', $cid)->where('elements_type', '=', 'Veer\\Models\\Category')->forceDelete();
     // We do not delete communications for deleted items
     return true;
 }
Example #2
0
 /**
  * Attach Parent Category
  * 
  */
 protected function attachParentCategory($cid, $parent_id, $category)
 {
     $check = \Veer\Models\CategoryPivot::where('child_id', '=', $cid)->where('parent_id', '=', $parent_id)->first();
     if (!$check) {
         $category->parentcategories()->attach($parent_id);
         event('veer.message.center', trans('veeradmin.category.parent.new'));
     }
 }
Example #3
0
 /**
  * Change parent Category in the child Category (detach from current).
  *
  * @helper Model attach|detach
  * @param int $child_id
  * @param int $parent_id
  * @param int|null $current_parent_id
  * @return \Veer\Services\Administration\Elements\Category
  */
 public function updateChildParent($child_id, $parent_id, $current_parent_id = null)
 {
     if (empty($current_parent_id)) {
         $current_parent_id = $this->id;
     }
     $check = \Veer\Models\CategoryPivot::where('child_id', '=', $child_id)->where('parent_id', '=', $parent_id)->first();
     if (!$check) {
         // update child's parent
         $category = \Veer\Models\Category::find($child_id);
         if (is_object($category)) {
             $category->parentcategories()->detach($current_parent_id);
             $category->parentcategories()->attach($parent_id);
             event('veer.message.center', trans('veeradmin.category.child.parent'));
         }
     }
     return $this;
 }