search and filtering
This commit is contained in:
@@ -11,17 +11,93 @@
|
||||
@endauth
|
||||
</div>
|
||||
|
||||
<!-- Categories Filter -->
|
||||
<div class="mb-4">
|
||||
<a href="{{ route('products.index') }}" class="btn btn-sm {{ !request('category') ? 'btn-primary' : 'btn-outline-primary' }}">
|
||||
All Categories
|
||||
</a>
|
||||
@foreach($categories as $category)
|
||||
<a href="{{ route('products.index', ['category' => $category->id]) }}"
|
||||
class="btn btn-sm {{ request('category') == $category->id ? 'btn-primary' : 'btn-outline-primary' }}">
|
||||
{{ $category->name }}
|
||||
</a>
|
||||
@endforeach
|
||||
<!-- Search & Filter Form -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<form method="GET" action="{{ route('products.index') }}" id="filterForm">
|
||||
<div class="row g-3">
|
||||
<!-- Search Input -->
|
||||
<div class="col-md-4">
|
||||
<label for="search" class="form-label fw-semibold">Search Products</label>
|
||||
<input
|
||||
type="text"
|
||||
name="search"
|
||||
id="search"
|
||||
value="{{ request('search') }}"
|
||||
class="form-control"
|
||||
placeholder="Search by title or description..."
|
||||
>
|
||||
</div>
|
||||
|
||||
<!-- Category Filter -->
|
||||
<div class="col-md-3">
|
||||
<label for="category" class="form-label fw-semibold">Category</label>
|
||||
<select name="category" id="category" class="form-select">
|
||||
<option value="">All Categories</option>
|
||||
@foreach($categories as $category)
|
||||
<option value="{{ $category->id }}" {{ request('category') == $category->id ? 'selected' : '' }}>
|
||||
{{ $category->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Date Range Filter -->
|
||||
<div class="col-md-2">
|
||||
<label for="date_range" class="form-label fw-semibold">Time Period</label>
|
||||
<select name="date_range" id="date_range" class="form-select">
|
||||
<option value="">All Time</option>
|
||||
<option value="today" {{ request('date_range') === 'today' ? 'selected' : '' }}>Today</option>
|
||||
<option value="week" {{ request('date_range') === 'week' ? 'selected' : '' }}>This Week</option>
|
||||
<option value="month" {{ request('date_range') === 'month' ? 'selected' : '' }}>This Month</option>
|
||||
<option value="year" {{ request('date_range') === 'year' ? 'selected' : '' }}>This Year</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Sort By -->
|
||||
<div class="col-md-2">
|
||||
<label for="sort" class="form-label fw-semibold">Sort By</label>
|
||||
<select name="sort" id="sort" class="form-select">
|
||||
<option value="newest" {{ request('sort') === 'newest' || !request('sort') ? 'selected' : '' }}>Newest</option>
|
||||
<option value="popular" {{ request('sort') === 'popular' ? 'selected' : '' }}>Most Popular</option>
|
||||
<option value="oldest" {{ request('sort') === 'oldest' ? 'selected' : '' }}>Oldest</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="col-md-1 d-flex align-items-end">
|
||||
<div class="btn-group w-100" role="group">
|
||||
<button type="submit" class="btn btn-primary" title="Apply Filters">
|
||||
<i class="bi bi-search"></i>
|
||||
</button>
|
||||
<a href="{{ route('products.index') }}" class="btn btn-outline-secondary" title="Clear Filters">
|
||||
<i class="bi bi-x-circle"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if(request()->hasAny(['search', 'category', 'date_range', 'sort']))
|
||||
<div class="mt-3">
|
||||
<small class="text-muted">
|
||||
<strong>Active Filters:</strong>
|
||||
@if(request('search'))
|
||||
<span class="badge bg-secondary me-1">Search: "{{ request('search') }}"</span>
|
||||
@endif
|
||||
@if(request('category'))
|
||||
<span class="badge bg-secondary me-1">Category: {{ $categories->find(request('category'))->name ?? 'Unknown' }}</span>
|
||||
@endif
|
||||
@if(request('date_range'))
|
||||
<span class="badge bg-secondary me-1">Period: {{ ucfirst(request('date_range')) }}</span>
|
||||
@endif
|
||||
@if(request('sort') && request('sort') !== 'newest')
|
||||
<span class="badge bg-secondary me-1">Sort: {{ ucfirst(request('sort')) }}</span>
|
||||
@endif
|
||||
</small>
|
||||
</div>
|
||||
@endif
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if(session('success'))
|
||||
@@ -31,6 +107,15 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Results Summary -->
|
||||
@if($products->total() > 0)
|
||||
<div class="mb-3">
|
||||
<p class="text-muted">
|
||||
Showing {{ $products->firstItem() }} to {{ $products->lastItem() }} of {{ $products->total() }} product(s)
|
||||
</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Products Grid -->
|
||||
<div class="row">
|
||||
@forelse($products as $product)
|
||||
@@ -44,7 +129,14 @@
|
||||
</div>
|
||||
@endif
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title">{{ $product->title }}</h5>
|
||||
<div class="d-flex justify-content-between align-items-start mb-2">
|
||||
<h5 class="card-title mb-0">{{ $product->title }}</h5>
|
||||
@if(isset($product->upvotes_count))
|
||||
<span class="badge bg-primary rounded-pill">
|
||||
<i class="bi bi-arrow-up"></i> {{ $product->upvotes_count }}
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
<p class="card-text text-muted small mb-2">
|
||||
<span class="badge bg-secondary">{{ $product->category->name }}</span>
|
||||
</p>
|
||||
@@ -62,16 +154,22 @@
|
||||
@empty
|
||||
<div class="col-md-12">
|
||||
<div class="alert alert-info">
|
||||
No products found. Be the first to submit one!
|
||||
@if(request()->hasAny(['search', 'category', 'date_range']))
|
||||
No products found matching your filters. Try adjusting your search criteria.
|
||||
@else
|
||||
No products found. Be the first to submit one!
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="d-flex justify-content-center">
|
||||
{{ $products->links() }}
|
||||
</div>
|
||||
@if($products->hasPages())
|
||||
<div class="d-flex justify-content-center">
|
||||
{{ $products->links() }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user