public function deleteRelatedTagsAndCategory($postType)
    {
        $categories = Category::where("postTypeID", $postType->postTypeID);
        $categoryIDs = $categories->pluck('categoryID')->toArray();
        $categoriesRelations = (new CategoryRelation)->setTable($postType->slug."_categories")->whereIn("categoryID", $categoryIDs);

        $tags = Tag::where("postTypeID", $postType->postTypeID);
        $tagIDs = $tags->pluck('tagID')->toArray();
        $tagsRelations = (new TagRelation)->setTable($postType->slug."_tags")->whereIn("tagID", $tagIDs);

        // return false if any delete failed
        if(($tagsRelations->count() && !$tagsRelations->delete()) 
            || ($categoriesRelations->count() && !$categoriesRelations->delete()) 
            || ($tags->count() && !$tags->delete()) 
            || ($categories->count() && !$categories->delete())
        ) {
            return false;
        }else{
            Schema::drop($postType->slug."_media");
            if($postType->hasCategories) {
                Schema::drop($postType->slug."_categories");
            }
            if($postType->hasTags) {
                Schema::drop($postType->slug."_tags");
            }
        }
        return true;
    }
public function deleteRelatedTagsAndCategory($postType)
    {
        $categories = Category::where("postTypeID", $postType->postTypeID);
        $categoryIDs = $categories->pluck('categoryID')->toArray();
        $categoriesRelations = (new CategoryRelation)->setTable($postType->slug."_categories")->whereIn("categoryID", $categoryIDs);

        $tags = Tag::where("postTypeID", $postType->postTypeID);
        $tagIDs = $tags->pluck('tagID')->toArray();
        $tagsRelations = (new TagRelation)->setTable($postType->slug."_tags")->whereIn("tagID", $tagIDs);

        // return false if any delete failed
        if(($tagsRelations->count() && !$tagsRelations->delete()) 
            || ($categoriesRelations->count() && !$categoriesRelations->delete()) 
            || ($tags->count() && !$tags->delete()) 
            || ($categories->count() && !$categories->delete())
        ) {
            return false;
        }else{
            Schema::drop($postType->slug."_media");
            if($postType->hasCategories) {
                Schema::drop($postType->slug."_categories");
            }
            if($postType->hasTags) {
                Schema::drop($postType->slug."_tags");
            }
        }
        return true;
    }
public function deleteRelatedTagsAndCategory ( $ postType ) { $ categories = Category :: where ( "postTypeID" , $ postType -> postTypeID ) ; $ categoryIDs = $ categories -> pluck ( 'categoryID' ) -> toArray ( ) ; $ categoriesRelations = ( new CategoryRelation ) -> setTable ( $ postType -> slug . "_categories" ) -> whereIn ( "categoryID" , $ categoryIDs ) ; $ tags = Tag :: where ( "postTypeID" , $ postType -> postTypeID ) ; $ tagIDs = $ tags -> pluck ( 'tagID' ) -> toArray ( ) ; $ tagsRelations = ( new TagRelation ) -> setTable ( $ postType -> slug . "_tags" ) -> whereIn ( "tagID" , $ tagIDs ) ; // return false if any delete failed if ( ( $ tagsRelations -> count ( ) && ! $ tagsRelations -> delete ( ) ) || ( $ categoriesRelations -> count ( ) && ! $ categoriesRelations -> delete ( ) ) || ( $ tags -> count ( ) && ! $ tags -> delete ( ) ) || ( $ categories -> count ( ) && ! $ categories -> delete ( ) ) ) { return false ; } else { Schema :: drop ( $ postType -> slug . "_media" ) ; if ( $ postType -> hasCategories ) { Schema :: drop ( $ postType -> slug . "_categories" ) ; } if ( $ postType -> hasTags ) { Schema :: drop ( $ postType -> slug . "_tags" ) ; } } return true ; }
Delete categories and tags with the relations for a post type.

@param  int $postTypeID
@return bool
Delete categories and tags with the relations for a post type .