Files
ai-nav/web10/app/Http/Controllers/HomeController.php

50 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2026-02-05 22:22:10 +08:00
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Product;
use App\Models\SiteSetting;
class HomeController extends Controller
{
public function index()
{
$featuredLimit = (int) SiteSetting::value('home_featured_limit', 8);
$newLimit = (int) SiteSetting::value('home_new_limit', 8);
$categoryLimit = (int) SiteSetting::value('home_category_limit', 20);
$featuredProducts = Product::published()
->featured()
->orderBy('sort')
->orderByDesc('hot_score')
->limit($featuredLimit)
->get();
$newProducts = Product::published()
->orderByDesc('sort')
->orderByDesc('created_at')
->limit($newLimit)
->get();
$categories = Category::with([
'children',
'products' => function ($query) use ($categoryLimit) {
$query->published()
->orderBy('sort')
->orderByDesc('hot_score')
->limit($categoryLimit);
},
])
->whereNull('parent_id')
->orderBy('sort')
->get();
2026-02-07 22:55:07 +08:00
return view('frontend.home', [
2026-02-05 22:22:10 +08:00
'featuredProducts' => $featuredProducts,
'newProducts' => $newProducts,
'categories' => $categories,
]);
}
}