Home > database >  Recursive function count In laravel
Recursive function count In laravel

Time:04-27

Please help me out with the Recursive function in the model, I want a count on multilevel subcategories.

$userChild = Referral::with(['get_children'])->where('user_id',Auth::id())->get();

CodePudding user response:

You can get the count using withCount Check the below URL for the more detail:

More detail here

CodePudding user response:

In magento e-commerce the category path add two columns to resolve easily this problem. If you can change it, will help you in the future. Magento category table is like this.

id path level
1 1 1
2 1/2 2
3 1/3 2
4 1/2/1 3
5 2 1
6 2/1 2

With this structure, you can use like to find all level "select * from table where path like "1/%"

  • Related