product submission

This commit is contained in:
2026-02-06 14:56:56 +02:00
parent b2fd2a5eac
commit 2e1ce0d93b
15 changed files with 1673 additions and 0 deletions
+149
View File
@@ -0,0 +1,149 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h3 class="mb-0">Submit a Product</h3>
</div>
<div class="card-body">
<form method="POST" action="{{ route('products.store') }}" enctype="multipart/form-data">
@csrf
<!-- Title -->
<div class="mb-3">
<label for="title" class="form-label">Product Title <span class="text-danger">*</span></label>
<input type="text"
class="form-control @error('title') is-invalid @enderror"
id="title"
name="title"
value="{{ old('title') }}"
required
maxlength="255"
placeholder="e.g., My Awesome Product">
@error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<small class="form-text text-muted">A catchy, descriptive title for your product.</small>
</div>
<!-- Description -->
<div class="mb-3">
<label for="description" class="form-label">Description <span class="text-danger">*</span></label>
<textarea class="form-control @error('description') is-invalid @enderror"
id="description"
name="description"
rows="5"
required
placeholder="Tell us about your product...">{{ old('description') }}</textarea>
@error('description')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<small class="form-text text-muted">Provide a detailed description of your product (what it does, key features, etc.).</small>
</div>
<!-- Website URL -->
<div class="mb-3">
<label for="website_url" class="form-label">Website URL <span class="text-danger">*</span></label>
<input type="url"
class="form-control @error('website_url') is-invalid @enderror"
id="website_url"
name="website_url"
value="{{ old('website_url') }}"
required
placeholder="https://example.com">
@error('website_url')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<small class="form-text text-muted">The full URL to your product's website or landing page.</small>
</div>
<!-- Category -->
<div class="mb-3">
<label for="category_id" class="form-label">Category <span class="text-danger">*</span></label>
<select class="form-select @error('category_id') is-invalid @enderror"
id="category_id"
name="category_id"
required>
<option value="">Select a category...</option>
@foreach($categories as $category)
<option value="{{ $category->id }}" {{ old('category_id') == $category->id ? 'selected' : '' }}>
{{ $category->name }}
</option>
@endforeach
</select>
@error('category_id')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<small class="form-text text-muted">Choose the category that best fits your product.</small>
</div>
<!-- Thumbnail -->
<div class="mb-3">
<label for="thumbnail" class="form-label">Product Thumbnail</label>
<input type="file"
class="form-control @error('thumbnail') is-invalid @enderror"
id="thumbnail"
name="thumbnail"
accept="image/*">
@error('thumbnail')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<small class="form-text text-muted">Upload a product screenshot or logo (JPEG, PNG, or GIF, max 2MB).</small>
</div>
<!-- Image Preview -->
<div class="mb-3" id="imagePreview" style="display: none;">
<label class="form-label">Preview:</label>
<div>
<img id="preview" src="#" alt="Thumbnail preview" style="max-width: 300px; max-height: 300px;" class="img-thumbnail">
</div>
</div>
<!-- Submit Button -->
<div class="d-flex justify-content-between">
<a href="{{ route('products.index') }}" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-primary">Submit Product</button>
</div>
<div class="alert alert-info mt-3" role="alert">
<strong>Note:</strong> Your product will be reviewed by our moderators before it appears on the site.
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
document.getElementById('thumbnail').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('preview').src = e.target.result;
document.getElementById('imagePreview').style.display = 'block';
}
reader.readAsDataURL(file);
} else {
document.getElementById('imagePreview').style.display = 'none';
}
});
</script>
@endpush
@endsection
+152
View File
@@ -0,0 +1,152 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h3 class="mb-0">Edit Product</h3>
</div>
<div class="card-body">
<form method="POST" action="{{ route('products.update', $product) }}" enctype="multipart/form-data">
@csrf
@method('PUT')
<!-- Title -->
<div class="mb-3">
<label for="title" class="form-label">Product Title <span class="text-danger">*</span></label>
<input type="text"
class="form-control @error('title') is-invalid @enderror"
id="title"
name="title"
value="{{ old('title', $product->title) }}"
required
maxlength="255">
@error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Description -->
<div class="mb-3">
<label for="description" class="form-label">Description <span class="text-danger">*</span></label>
<textarea class="form-control @error('description') is-invalid @enderror"
id="description"
name="description"
rows="5"
required>{{ old('description', $product->description) }}</textarea>
@error('description')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Website URL -->
<div class="mb-3">
<label for="website_url" class="form-label">Website URL <span class="text-danger">*</span></label>
<input type="url"
class="form-control @error('website_url') is-invalid @enderror"
id="website_url"
name="website_url"
value="{{ old('website_url', $product->website_url) }}"
required>
@error('website_url')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Category -->
<div class="mb-3">
<label for="category_id" class="form-label">Category <span class="text-danger">*</span></label>
<select class="form-select @error('category_id') is-invalid @enderror"
id="category_id"
name="category_id"
required>
<option value="">Select a category...</option>
@foreach($categories as $category)
<option value="{{ $category->id }}"
{{ old('category_id', $product->category_id) == $category->id ? 'selected' : '' }}>
{{ $category->name }}
</option>
@endforeach
</select>
@error('category_id')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Current Thumbnail -->
@if($product->thumbnail_url)
<div class="mb-3">
<label class="form-label">Current Thumbnail:</label>
<div>
<img src="{{ $product->thumbnail_url }}" alt="{{ $product->title }}" style="max-width: 300px; max-height: 300px;" class="img-thumbnail">
</div>
</div>
@endif
<!-- New Thumbnail -->
<div class="mb-3">
<label for="thumbnail" class="form-label">
{{ $product->thumbnail_url ? 'Replace Thumbnail' : 'Product Thumbnail' }}
</label>
<input type="file"
class="form-control @error('thumbnail') is-invalid @enderror"
id="thumbnail"
name="thumbnail"
accept="image/*">
@error('thumbnail')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<small class="form-text text-muted">JPEG, PNG, or GIF, max 2MB.</small>
</div>
<!-- Image Preview -->
<div class="mb-3" id="imagePreview" style="display: none;">
<label class="form-label">New Preview:</label>
<div>
<img id="preview" src="#" alt="Thumbnail preview" style="max-width: 300px; max-height: 300px;" class="img-thumbnail">
</div>
</div>
<!-- Submit Button -->
<div class="d-flex justify-content-between">
<a href="{{ route('products.show', $product) }}" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-primary">Update Product</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
document.getElementById('thumbnail').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('preview').src = e.target.result;
document.getElementById('imagePreview').style.display = 'block';
}
reader.readAsDataURL(file);
} else {
document.getElementById('imagePreview').style.display = 'none';
}
});
</script>
@endpush
@endsection
+78
View File
@@ -0,0 +1,78 @@
@extends('layouts.app')
@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>
<!-- 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
</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
<!-- 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">
<h5 class="card-title">{{ $product->title }}</h5>
<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">
No products found. Be the first to submit one!
</div>
</div>
@endforelse
</div>
<!-- Pagination -->
<div class="d-flex justify-content-center">
{{ $products->links() }}
</div>
</div>
</div>
</div>
@endsection
+168
View File
@@ -0,0 +1,168 @@
@extends('layouts.app')
@section('content')
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h1 class="mb-4">Product Management</h1>
@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
<!-- Status Filter -->
<div class="card mb-4">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<h5 class="mb-3">Filter by Status</h5>
<a href="{{ route('products.manage') }}"
class="btn btn-sm {{ !request('status') || request('status') == 'pending' ? 'btn-warning' : 'btn-outline-warning' }}">
Pending ({{ $statusCounts['pending'] }})
</a>
<a href="{{ route('products.manage', ['status' => 'approved']) }}"
class="btn btn-sm {{ request('status') == 'approved' ? 'btn-success' : 'btn-outline-success' }}">
Approved ({{ $statusCounts['approved'] }})
</a>
<a href="{{ route('products.manage', ['status' => 'rejected']) }}"
class="btn btn-sm {{ request('status') == 'rejected' ? 'btn-danger' : 'btn-outline-danger' }}">
Rejected ({{ $statusCounts['rejected'] }})
</a>
</div>
</div>
</div>
</div>
<!-- Products Table -->
<div class="card">
<div class="card-body">
@if($products->count() > 0)
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Thumbnail</th>
<th>Title</th>
<th>Category</th>
<th>Submitted By</th>
<th>Status</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($products as $product)
<tr>
<td>
@if($product->thumbnail_url)
<img src="{{ $product->thumbnail_url }}"
alt="{{ $product->title }}"
style="width: 60px; height: 60px; object-fit: cover;"
class="rounded">
@else
<div class="bg-light d-flex align-items-center justify-content-center rounded"
style="width: 60px; height: 60px;">
<span class="text-muted small">No img</span>
</div>
@endif
</td>
<td>
<a href="{{ route('products.show', $product) }}" class="fw-bold text-decoration-none">
{{ $product->title }}
</a>
<br>
<small class="text-muted">{{ Str::limit($product->description, 60) }}</small>
</td>
<td>
<span class="badge bg-secondary">{{ $product->category->name }}</span>
</td>
<td>
<a href="{{ route('profile.show', $product->user) }}">
{{ $product->user->name }}
</a>
</td>
<td>
@if($product->isPending())
<span class="badge bg-warning text-dark">Pending</span>
@elseif($product->isApproved())
<span class="badge bg-success">Approved</span>
@elseif($product->isRejected())
<span class="badge bg-danger">Rejected</span>
@endif
</td>
<td>
<small>{{ $product->created_at->format('M j, Y') }}</small>
<br>
<small class="text-muted">{{ $product->created_at->diffForHumans() }}</small>
</td>
<td>
<div class="btn-group btn-group-sm" role="group">
@if($product->isPending() || $product->isRejected())
<form action="{{ route('products.approve', $product) }}" method="POST" class="d-inline">
@csrf
<button type="submit" class="btn btn-success btn-sm" title="Approve">
✓
</button>
</form>
@endif
@if($product->isPending() || $product->isApproved())
<form action="{{ route('products.reject', $product) }}" method="POST" class="d-inline">
@csrf
<button type="submit"
class="btn btn-danger btn-sm"
title="Reject"
onclick="return confirm('Are you sure you want to reject this product?');">
✗
</button>
</form>
@endif
<a href="{{ route('products.show', $product) }}" class="btn btn-info btn-sm" title="View">
👁
</a>
@can('edit-product', $product)
<a href="{{ route('products.edit', $product) }}" class="btn btn-primary btn-sm" title="Edit">
✎
</a>
@endcan
@can('delete-product', $product)
<form action="{{ route('products.destroy', $product) }}" method="POST" class="d-inline">
@csrf
@method('DELETE')
<button type="submit"
class="btn btn-danger btn-sm"
title="Delete"
onclick="return confirm('Are you sure you want to delete this product permanently?');">
🗑
</button>
</form>
@endcan
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="d-flex justify-content-center mt-4">
{{ $products->appends(['status' => request('status')])->links() }}
</div>
@else
<div class="alert alert-info">
No products found with status: {{ request('status', 'pending') }}
</div>
@endif
</div>
</div>
</div>
</div>
</div>
@endsection
+114
View File
@@ -0,0 +1,114 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
@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
<div class="card">
<div class="card-body">
<!-- Product Header -->
<div class="d-flex justify-content-between align-items-start mb-4">
<div class="flex-grow-1">
<h1 class="mb-2">{{ $product->title }}</h1>
<p class="text-muted mb-0">
<span class="badge bg-secondary">{{ $product->category->name }}</span>
@if($product->isPending())
<span class="badge bg-warning text-dark">Pending Review</span>
@elseif($product->isApproved())
<span class="badge bg-success">Approved</span>
@elseif($product->isRejected())
<span class="badge bg-danger">Rejected</span>
@endif
</p>
</div>
<div>
@can('edit-product', $product)
<a href="{{ route('products.edit', $product) }}" class="btn btn-sm btn-outline-primary">Edit</a>
@endcan
@can('delete-product', $product)
<form action="{{ route('products.destroy', $product) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this product?');">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
</form>
@endcan
</div>
</div>
<!-- Product Thumbnail -->
@if($product->thumbnail_url)
<div class="mb-4">
<img src="{{ $product->thumbnail_url }}" alt="{{ $product->title }}" class="img-fluid rounded" style="max-height: 400px;">
</div>
@endif
<!-- Product Description -->
<div class="mb-4">
<h4>About</h4>
<p class="lead">{{ $product->description }}</p>
</div>
<!-- Product Links -->
<div class="mb-4">
<a href="{{ $product->website_url }}" target="_blank" rel="noopener" class="btn btn-primary btn-lg">
Visit Website →
</a>
</div>
<!-- Product Metadata -->
<hr>
<div class="row text-muted small">
<div class="col-md-6">
<strong>Submitted by:</strong>
<a href="{{ route('profile.show', $product->user) }}">{{ $product->user->name }}</a>
</div>
<div class="col-md-6 text-md-end">
<strong>Submitted:</strong> {{ $product->created_at->format('F j, Y') }}
</div>
</div>
@if($product->isApproved() && $product->approved_at)
<div class="row text-muted small mt-2">
<div class="col-md-12">
<strong>Approved:</strong> {{ $product->approved_at->format('F j, Y') }}
</div>
</div>
@endif
</div>
</div>
<!-- Moderator Actions -->
@can('approve-product')
@if($product->isPending() || $product->isRejected())
<div class="card mt-3">
<div class="card-header bg-warning">
<h5 class="mb-0">Moderator Actions</h5>
</div>
<div class="card-body">
<form action="{{ route('products.approve', $product) }}" method="POST" class="d-inline">
@csrf
<button type="submit" class="btn btn-success">Approve Product</button>
</form>
<form action="{{ route('products.reject', $product) }}" method="POST" class="d-inline">
@csrf
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to reject this product?');">Reject Product</button>
</form>
</div>
</div>
@endif
@endcan
<div class="mt-3">
<a href="{{ route('products.index') }}" class="btn btn-secondary">← Back to Products</a>
</div>
</div>
</div>
</div>
@endsection