Skip to content

Magento 2 get all category ids sorted by the category tree

is there any way we can get all category ids like its displayed in admin in Magento ver. 2.4.3 ?

I have tried

     **
     * Get Category
     */
    public function getCategory($categoryId) 
    {
        $category = $this->_categoryFactory->create();
        $category->load($categoryId)->setOrder('entity_id', 'ASC');
        return $category;
    }

but this did not work.

Thank you