This commit is contained in:
cjd
2026-02-05 22:22:10 +08:00
parent fef9fe0c31
commit bf3a2e6971
273 changed files with 30605 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Tag;
use App\Models\SiteSetting;
class CategoryController extends Controller
{
public function index()
{
$categories = Category::withCount('products')
->whereNull('parent_id')
->orderBy('sort')
->get();
return view('category.index', [
'categories' => $categories,
]);
}
public function show(string $slug)
{
$category = Category::where('slug', $slug)->firstOrFail();
$perPage = (int) SiteSetting::value('list_page_size', 20);
$moreThreshold = (int) SiteSetting::value('list_more_threshold', 20);
$tagSlug = request()->query('tag');
$pricing = request()->query('pricing');
$tags = Tag::orderBy('name')->get();
$products = $category->products()
->published()
->when($tagSlug, function ($builder) use ($tagSlug) {
$builder->whereHas('tags', function ($query) use ($tagSlug) {
$query->where('slug', $tagSlug);
});
})
->when($pricing, function ($builder) use ($pricing) {
$builder->where('pricing_type', $pricing);
})
->orderBy('sort')
->orderByDesc('hot_score')
->paginate($perPage);
return view('category.show', [
'category' => $category,
'products' => $products,
'moreThreshold' => $moreThreshold,
'tags' => $tags,
'tagSlug' => $tagSlug,
'pricing' => $pricing,
]);
}
}