app/Category.php
/**
     * Delete the give category id  and all his sub-category and relative posts
     *
     * @param $id - The category id to delete
     * @return bool
     */
Delete the give category id  and all his sub-category and relative posts
@param $id - The category id to delete
@return bool
Delete the give category id and all his sub - category and relative posts @param $id - The category id to delete @return bool
public function deleteCategoryAndSubcategory($id)
    {
        $sub_categories = $this->linearizeCategoryArray($this->listTreeCategories($id));
        if(count($sub_categories)>0) {
            foreach ($sub_categories as $sub_category) {
               $sub_category = $this->find($sub_category['id']);
                $sub_category->posts()->delete();
                $sub_category->posts()->detach();
                if (!$this->whereId($sub_category['id'])->delete()) {
                    return false;
                }
            }
        }
      if ($this->whereId($id)->delete()) {
            return true;
        }
        return false;
    }
public function deleteCategoryAndSubcategory ( $ id ) { $ sub_categories = $ this -> linearizeCategoryArray ( $ this -> listTreeCategories ( $ id ) ) ; if ( count ( $ sub_categories ) > 0 ) { foreach ( $ sub_categories as $ sub_category ) { $ sub_category = $ this -> find ( $ sub_category [ 'id' ] ) ; $ sub_category -> posts ( ) -> delete ( ) ; $ sub_category -> posts ( ) -> detach ( ) ; if ( ! $ this -> whereId ( $ sub_category [ 'id' ] ) -> delete ( ) ) { return false ; } } } if ( $ this -> whereId ( $ id ) -> delete ( ) ) { return true ; } return false ; }
Delete the give category id  and all his sub-category and relative posts
 @param $id - The category id to delete
 @return bool
Delete the give category id and all his sub - category and relative posts @param $id - The category id to delete @return bool
// Search if this sub-categories as post and // Delete All posts in this category // Delete entry in pivot