feat: product badges and show page layout

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-10-17 15:56:58 +03:00
co-authored by Claude Sonnet 5.5
parent 029689407b
commit 9920fafab6
12 changed files with 382 additions and 63 deletions
+41 -3
View File
@@ -110,7 +110,11 @@ class ProductController extends Controller
'category_id' => 'required|exists:categories,id',
'tags' => 'nullable|array',
'tags.*' => 'exists:tags,id',
]);
] + $this->detailRules());
foreach (array_keys(Product::BADGES) as $badge) {
$validated[$badge] = $request->boolean($badge);
}
$validated['user_id'] = Auth::id();
$validated['status'] = 'pending';
@@ -128,6 +132,8 @@ class ProductController extends Controller
$product->tags()->attach($request->tags);
}
$this->syncDetails($request, $product);
return redirect()->route('products.show', $product)
->with('success', 'Product submitted successfully! It will be reviewed by our moderators.');
}
@@ -142,7 +148,7 @@ class ProductController extends Controller
abort(404);
}
$product->load(['user', 'category', 'comments.user', 'upvotes', 'bookmarks']);
$product->load(['user', 'category', 'tags', 'comments.user', 'upvotes', 'bookmarks']);
return view('products.show', compact('product'));
}
@@ -174,7 +180,16 @@ class ProductController extends Controller
'category_id' => 'required|exists:categories,id',
'tags' => 'nullable|array',
'tags.*' => 'exists:tags,id',
]);
] + $this->detailRules());
// Badges are locked for non-moderators once the product is approved
if ($product->status !== 'approved' || Auth::user()->hasAnyRole(['moderator', 'admin'])) {
foreach (array_keys(Product::BADGES) as $badge) {
$validated[$badge] = $request->boolean($badge);
}
} else {
$validated = array_diff_key($validated, Product::BADGES);
}
// Handle thumbnail upload
if ($request->hasFile('thumbnail')) {
@@ -189,6 +204,8 @@ class ProductController extends Controller
$product->update($validated);
$this->syncDetails($request, $product);
// Sync tags (will remove old tags and add new ones)
$product->tags()->sync($request->tags ?? []);
@@ -196,6 +213,27 @@ class ProductController extends Controller
->with('success', 'Product updated successfully!');
}
/**
* Validation rules for the product detail fields.
*/
protected function detailRules(): array
{
return [
'free_tier' => 'boolean',
'open_source' => 'boolean',
'eu_hosted' => 'boolean',
'eu_made' => 'boolean',
];
}
/**
* Sync related product detail data (badges are stored on the product itself).
*/
protected function syncDetails(Request $request, Product $product): void
{
//
}
/**
* Remove the specified product from storage.
*/