app/User.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 deletePostAndUser($id)
    {
        $user_posts = $this->find($id)->posts()->get()->toArray();
        if(count($user_posts)>0) {
            foreach ($user_posts as $post) {
                Post::find($post['id'])->delete();
                if( !\DB::table('category_post')->where('post_id', '=', $post['id'])->delete() ){
                    return false;
                }
            }
        }
        if ($this->whereId($id)->delete()) {
            return true;
        }
        return false;
    }
public function deletePostAndUser ( $ id ) { $ user_posts = $ this -> find ( $ id ) -> posts ( ) -> get ( ) -> toArray ( ) ; if ( count ( $ user_posts ) > 0 ) { foreach ( $ user_posts as $ post ) { Post :: find ( $ post [ 'id' ] ) -> delete ( ) ; if ( ! \ DB :: table ( 'category_post' ) -> where ( 'post_id' , '=' , $ post [ '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
// Delete entry in pivot