How do I get all children that fall under a parent in eloquent?

前端 未结 6 2095
日久生厌
日久生厌 2021-01-04 21:45

In my database, I have a Categories table. Categories can have parent categories, making it a recursive relationship

I also have a products table. Each product falls

6条回答
  •  抹茶落季
    2021-01-04 22:27

    you better use nested sets models. you should use this data structure due to get fastest way to query in mysql with a simple way. with just a parent_id attribute,you don't know how deep your tree is and this make problem in knowing how many join you need. I offer you this excellent article. managing-hierarchical-data-in-mysql

    for those who use laravel framework, I prefer to suggest this amazing package:Baum

提交回复
热议问题