Back to JKShop Support

AlexeiKo
AlexeiKo

Hey, How can I get subcategories of some category? {{ category }} doesnt have such key/value only some nested thing... Please advice. Thanks a lot!

AlexeiKo
AlexeiKo

I made this: `

 ==
 <?php

 use Jiri\Jkshop\Models\Category;

 function onStart()
 {
     $currentCategoryId = Category::where('slug', '=',  $this->param('category'))->pluck('id');
     $subcategories = Category::where('parent_id', '=', $currentCategoryId)->get();
     $this['subcategories'] = $subcategories;
  }
 ?>

` but I dont like it. Any suggestions?

Jiri Kubak
Jiri Kubak

AlexeiKo said:

Hey, How can I get subcategories of some category? {{ category }} doesnt have such key/value only some nested thing... Please advice. Thanks a lot!

Hi Alex,

categories implement nested tree then you can check documentation there: https://octobercms.com/docs/database/traits#nested-tree

eg.: you can use $root->children()

AlexeiKo
AlexeiKo

thanks, checking

1-4 of 4