First I would define your database categories and subcategories table structures:
// A common rule is to not have more than one main category and one subcategory, everything else should go into a filter where you can define rest sub-subcategories (If you need to)
categories table
id - unique integer
name - unique string
slug - unique slug
// ... Everything else
subcategories table
id - unique integer
name - unique string
slug - unique slug
category_id - integer
// ... Everything else
And then I would bind categories with One To Many relationship:
// Category Model
public function subcategories()
{
return $this->hasMany(Subcategory::class);
}
That way you'll get all categories and subcategories you need, just bind them to what categories are for. For example you can bind items to your subcategory_id with One To Many relationship, and then just display your items using subcategory->products on your main category page:
// Your view
@foreach($category->subcategories as $subcategory)
@foreach($subcategory->products as $product)
<x-product-template>
{{ $product->name }} // ...
</x-product-template>
@endforeach
@endforeach
In your routes web.php file:
use App\Http\Controllers\CategoryController;
Route::get('categories/{category:slug}', [CategoryController::class, 'show'])->name('category.product'); // You don't need to define full path to your controller