@php use Modules\Core\Helpers\Helper; @endphp @extends('front::layouts.master') @section('title','E-SHOP || Blog Page') @section('content') @php $currentUrl = request()->path(); $categorySlug = null; if (strpos($currentUrl, 'blog-cat/') !== false) { $categorySlug = str_replace('blog-cat/', '', $currentUrl); } $categories = Helper::postCategoryList(); $currentCategory = $categorySlug ? $categories->where('slug', $categorySlug)->first() : null; @endphp @if($currentCategory)

Category: {{ $currentCategory->name }}

@endif

Blog Categories

@php // Get selected slugs from query parameter or from URL path $selectedSlugs = collect(explode(',', request()->query('category')))->filter(); // If we're on a single category page, add that slug to selected slugs if ($categorySlug) { $selectedSlugs->push($categorySlug); } @endphp
    @foreach(Helper::postCategoryList() as $i => $cat) @php $id = "cat_".$i; $checked = $selectedSlugs->contains($cat->slug); @endphp
  • @endforeach
@if($categorySlug || request()->has('category')) @endif
@php // Filter posts based on category slug from URL $filteredPosts = $posts; // 🔍 SEARCH FILTER if(request()->has('search') && !empty(request()->search)) { $search = strtolower(request()->search); $filteredPosts = $filteredPosts->filter(function($post) use ($search) { return str_contains(strtolower($post->title), $search) || str_contains(strtolower($post->summary), $search); }); } // 📂 CATEGORY FILTER if ($categorySlug && $currentCategory) { $filteredPosts = $filteredPosts->filter(function($post) use ($currentCategory) { return $post->cat_id == $currentCategory->id; }); } elseif (request()->has('category') && !empty(request()->category)) { $categorySlugs = explode(',', request()->category); $categoryIds = $categories->whereIn('slug', $categorySlugs)->pluck('id')->toArray(); $filteredPosts = $filteredPosts->filter(function($post) use ($categoryIds) { return in_array($post->cat_id, $categoryIds); }); } // ✅ ADD THIS (STATUS FILTER) $filteredPosts = $filteredPosts->filter(function($post) { return strtolower($post->status ?? '') === 'active'; }); @endphp @if($filteredPosts->count() > 0) @foreach($filteredPosts as $post)
{{ $post->title }}

{{ $post->created_at->format('d M Y') }} | @php $postCategory = $categories->where('id', $post->cat_id)->first(); @endphp {{ $postCategory->name ?? 'Uncategorized' }}

{{ $post->title }}

{!! html_entity_decode($post->summary) !!}

@endforeach
{{$posts->appends($_GET)->links('vendor.pagination.bootstrap-4')}}
@else
@if(request()->has('search') && request()->search)

No Blog Posts Found "{{ request('search') }}"

@endif

@if($currentCategory) There are currently no posts in the "{{ $currentCategory->name }}" category. @elseif(request()->has('category')) No posts match the selected categories. @else There are currently no blog posts available. Please check back later for updates and new content. @endif

@if($categorySlug || request()->anyFilled(['search', 'category', 'tag'])) Clear Filters @endif
@endif
@endsection @push('styles') @endpush @push('scripts') @endpush