init
This commit is contained in:
49
web10/app/Http/Controllers/HomeController.php
Normal file
49
web10/app/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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('home', [
|
||||
'featuredProducts' => $featuredProducts,
|
||||
'newProducts' => $newProducts,
|
||||
'categories' => $categories,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user