181 lines
9.9 KiB
PHP
181 lines
9.9 KiB
PHP
@extends('layouts.app')
|
|||
|
|
|
||
|
|
@php
|
||
|
|
$title = 'Discover Products - ' . config('app.name');
|
||
|
|
@endphp
|
||
|
|
|
||
|
|
@section('content')
|
||
|
|
<div class="container">
|
||
|
|
<div class="row">
|
||
|
|
<div class="col-md-12">
|
||
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||
|
|
<h1>Discover Products</h1>
|
||
|
|
@auth
|
||
|
|
<a href="{{ route('products.create') }}" class="btn btn-primary">Submit a Product</a>
|
||
|
|
@endauth
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 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'))
|
||
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||
|
|
{{ session('success') }}
|
||
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||
|
|
</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)
|
||
|
|
<div class="col-md-4 mb-4">
|
||
|
|
<div class="card h-100">
|
||
|
|
@if($product->thumbnail_url)
|
||
|
|
<img src="{{ $product->thumbnail_url }}" class="card-img-top" alt="{{ $product->title }}" style="height: 200px; object-fit: cover;">
|
||
|
|
@else
|
||
|
|
<div class="bg-light d-flex align-items-center justify-content-center" style="height: 200px;">
|
||
|
|
<span class="text-muted">No image</span>
|
||
|
|
</div>
|
||
|
|
@endif
|
||
|
|
<div class="card-body d-flex flex-column">
|
||
|
|
<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>
|
||
|
|
<p class="card-text flex-grow-1">{{ Str::limit($product->description, 100) }}</p>
|
||
|
|
<div class="mt-auto">
|
||
|
|
<a href="{{ route('products.show', $product) }}" class="btn btn-sm btn-primary">View Details</a>
|
||
|
|
<a href="{{ $product->website_url }}" target="_blank" rel="noopener" class="btn btn-sm btn-outline-primary">Visit Website</a>
|
||
|
|
</div>
|
||
|
|
<div class="mt-2 text-muted small">
|
||
|
|
By {{ $product->user->name }} · {{ $product->created_at->diffForHumans() }}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
@empty
|
||
|
|
<div class="col-md-12">
|
||
|
|
<div class="alert alert-info">
|
||
|
|
@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 -->
|
||
|
|
@if($products->hasPages())
|
||
|
|
<div class="d-flex justify-content-center">
|
||
|
|
{{ $products->links() }}
|
||
|
|
</div>
|
||
|
|
@endif
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
@endsection
|