How to get recursive children with custom constraint? #245
-
I have this structure in the Category model database: id, category_id, parent_id, title, total_products.
I do it this way and everything works:
But the result was not what I expected. The number of my categories has increased 5 times =)) How can I get the result of categories that have products in a tree?
thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Hi @ilyapokrov, $tree = Category::find(3)->descendantsAndSelf()->where('total_products', '!=', '0')->get(); |
Beta Was this translation helpful? Give feedback.
The
toTree()
isn't available inv1.6
, but your command should actually installv1.9.6
because that's the latest version compatible with Laravel 8. What operating system and terminal are you using?Try running
composer require staudenmeir/laravel-adjacency-list:"^1.9.6"
instead.