title: Sorting product Sort by category | WinterCMS/ OctoberCMS Plugin Builder
body: <p>Another question from a noob.<br />
  On the page, I need to get a list of Categories with Subcategories something like:</p>
  <ul>
  <li>Category 1
  <ul>
  <li>Subcategory1_Category1</li>
  <li>Subcategory2_Category1</li>
  </ul>
  </li>
  <li>Category 2
  <ul>
  <li>Subcategory1_Category2</li>
  <li>Subcategory2_Category 2</li>
  </ul>
  </li>
  </ul>
  <p>I have two models - Category and Subcategory.</p>
  <p>I'm added relationship
  Subcategory Model:</p>
  <pre><code>use \Winter\Storm\Database\Traits\SimpleTree;
  public $belongsTo = [
          'category' =&gt; [
              'AName\PName\Models\Category',
              'key' =&gt; 'category_id']
      ];
  </code></pre>
  <p>Catalog Components:</p>
  <pre><code>$this-&gt;page['categories'] = Category::get();
  $subcategories = $this-&gt;page['subcategories'] = Subcategory::where('category_id', $category-&gt;$id)-&gt;get();
  </code></pre>
  <p>I receive 'Undefined variable: category'<br />
  Where is the mistake?<br />
  Thanks in advance.</p>