xxxxxxxxxx
<!-- Start an unoredered list -->
<ul>
<!-- Loop through each category -->
@foreach ($categories as $category)
<!-- Include subcategories.blade.php file and pass the current category to it -->
@include('subcategories', ['category' => $category])
@endforeach
<ul>
xxxxxxxxxx
<!-- Displaying the current category -->
<li value="{{ $category->id }}">{{ $category->name}}
<!-- If category has children -->
@if (count($category->children) > 0)
<!-- Create a nested unordered list -->
<ul>
<!-- Loop through this category's children -->
@foreach ($category->children as $sub)
<!-- Call this blade file again (recursive) and pass the current subcategory to it -->
@include('subcategories', ['category' => $sub])
@endforeach
</ul>
@endif
</li>