def update_categories
      @post = LatoBlog::Post.find_by(id: params[:id])
      return unless check_post_presence

      params[:categories].each do |category_id, value|
        category = LatoBlog::Category.find_by(id: category_id)
        next if !category || category.meta_language != @post.meta_language

        category_post = LatoBlog::CategoryPost.find_by(lato_blog_post_id: @post.id, lato_blog_category_id: category.id)
        if value == 'true'
          LatoBlog::CategoryPost.create(lato_blog_post_id: @post.id, lato_blog_category_id: category.id) unless category_post
        else
          category_post.destroy if category_post
        end
      end
    end
def update_categories
      @post = LatoBlog::Post.find_by(id: params[:id])
      return unless check_post_presence

      params[:categories].each do |category_id, value|
        category = LatoBlog::Category.find_by(id: category_id)
        next if !category || category.meta_language != @post.meta_language

        category_post = LatoBlog::CategoryPost.find_by(lato_blog_post_id: @post.id, lato_blog_category_id: category.id)
        if value == 'true'
          LatoBlog::CategoryPost.create(lato_blog_post_id: @post.id, lato_blog_category_id: category.id) unless category_post
        else
          category_post.destroy if category_post
        end
      end
    end
This function updates the categories of a post.