@php
// Fetch featured items
$featuredItems = collect([]);
// Include the current category if it is featured (applies to all levels)
if ($displayCategory->featured_item) {
$featuredItems->push($displayCategory);
}
// Determine the level of the current category using breadcrumbs
$categoryLevel = count($breadcrumbs);
// Level 1: Only include featured immediate children (Level 2 sub-categories)
if ($categoryLevel === 1) {
$subCategories = \App\Models\Category::where('parent_id', $displayCategory->id)
->where('active', 1)
->where('featured_item', 1) // Only fetch featured sub-categories
->get();
$featuredItems = $featuredItems->merge($subCategories);
}
// Level 2: Include featured immediate children (Level 3 sub-sub-categories)
if ($categoryLevel === 2) {
$subSubCategories = \App\Models\Category::where('parent_id', $displayCategory->id)
->where('active', 1)
->where('featured_item', 1) // Only fetch featured sub-sub-categories
->get();
$featuredItems = $featuredItems->merge($subSubCategories);
}
// Level 3: Include featured siblings (other Level 3 categories under the same parent)
if ($categoryLevel === 3) {
$parentSubCategory = $displayCategory->parent;
if ($parentSubCategory) {
$featuredItems = $featuredItems->merge(
\App\Models\Category::where('parent_id', $parentSubCategory->id)
->where('featured_item', 1)
->where('id', '!=', $displayCategory->id)
->where('active', 1)
->orderBy('created_at', 'asc')
->get()
);
}
}
// Order by created_at and take top 4
$featuredItems = $featuredItems->sortBy('created_at')->take(4);
@endphp
@if($featuredItems->isNotEmpty())
Most Popular {{ $displayCategory->name }} in Dallas
@foreach($featuredItems as $item)
@php
// Determine the correct URL based on the category level
$itemUrl = [];
if ($categoryLevel === 1) {
// Level 1: Linking to Level 2 sub-categories (e.g., /dining/steakhouses)
$itemUrl = [$displayCategory->slug, $item->slug];
} elseif ($categoryLevel === 2) {
// Level 2: Linking to Level 3 sub-sub-categories (e.g., /dining/steakhouses/nuri)
$parentCategory = $displayCategory->parent;
$itemUrl = [$parentCategory->slug, $displayCategory->slug, $item->slug];
} elseif ($categoryLevel === 3) {
// Level 3: Linking to sibling Level 3 categories (e.g., from /dining/steakhouses/nuri to /dining/steakhouses/nick-sams)
$parentCategory = $displayCategory->parent->parent;
$subCategory = $displayCategory->parent;
$itemUrl = [$parentCategory->slug, $subCategory->slug, $item->slug];
}
@endphp
No related options available for {{ $displayCategory->name }}.
@endif
@endif
Venues
@if($subSubCategoriesForVenues->isNotEmpty())
@php
// Group sub-sub-categories by their parent (Level 2) sub-category
$groupedVenues = $subSubCategoriesForVenues->groupBy('parent_id');
@endphp
@if($groupedVenues->isNotEmpty())
@foreach($groupedVenues as $parentId => $venues)
@php
$parentCategory = \App\Models\Category::find($parentId);
if (!$parentCategory) continue; // Skip if parent not found
@endphp