Hàm có cấu trúc như sau:
get_list_product_categories($parent_id, $onlyShowPublished, $locale);
Trong đó:
$parent_idlà ID của danh mục cha, mặc định là 0.$onlyShowPublishedchỉ hiện các bài đã được đăng tải, mặc định làtrue.$localengôn ngữ cố định, mặc định lànullsẽ lấy theo ngôn ngữ trang.
Kết quả trả về là một collection và mỗi phần tử là một đối tượng Categories.
Ví dụ, lấy danh mục widgets và đệ qui tất cả chuyên mục con, trong tập tin sidebar.blade.php ở theme sẽ như sau:
<aside class="widget categories-widget">
<h3 class="widget-title">Danh mục sản phẩm</h3>
@include('theme::partial.category_item', ['categories' => get_list_product_categories(0)])
</aside>
Trong partial/category_item.blade.php sẽ có nội dung như sau:
<ul>
@foreach($categories as $category)
<li>
<a href="{{ $category->language('link') }}">
{{ $category->language('name') }}
</a>
@if($category->children_count > 0)
@include('theme::partial.category_item', ['categories' => get_list_product_categories($category->id)])
@endif
</li>
@endforeach
</ul>
