50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?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();
|
|
|
|
return view('frontend.home', [
|
|
'featuredProducts' => $featuredProducts,
|
|
'newProducts' => $newProducts,
|
|
'categories' => $categories,
|
|
]);
|
|
}
|
|
}
|