init
This commit is contained in:
53
app/Http/Controllers/Site/HomeController.php
Normal file
53
app/Http/Controllers/Site/HomeController.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Site;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiModel;
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use App\Models\Guide;
|
||||
use App\Models\Tool;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
{
|
||||
$payload = Cache::remember('home_page_payload_v2', now()->addMinutes(10), function (): array {
|
||||
$latestTools = Tool::published()->latest('published_at')->limit(10)->get();
|
||||
$latestModels = AiModel::published()->orderByDesc('total_score')->limit(10)->get();
|
||||
$latestArticles = Article::published()->latest('published_at')->limit(10)->get();
|
||||
$latestGuides = Guide::published()->latest('published_at')->limit(10)->get();
|
||||
|
||||
return [
|
||||
'stats' => [
|
||||
'tools' => Tool::published()->count(),
|
||||
'models' => AiModel::published()->count(),
|
||||
'articles' => Article::published()->count(),
|
||||
'guides' => Guide::published()->count(),
|
||||
],
|
||||
'featuredTools' => $latestTools->take(4),
|
||||
'featuredModels' => $latestModels->take(4),
|
||||
'toolList' => $latestTools->take(8),
|
||||
'modelList' => $latestModels->take(8),
|
||||
'articleList' => $latestArticles->take(8),
|
||||
'guideList' => $latestGuides->take(8),
|
||||
'hotKeywords' => [
|
||||
'AI导航', '工作流自动化', '多模态模型', 'AIGC 设计', 'AI 编程助手', '提示词模板', '行业快讯', '模型评测',
|
||||
],
|
||||
'moduleCategories' => [
|
||||
'tools' => Category::query()->where('type', 'tool')->where('is_active', true)->orderBy('name')->limit(8)->get(),
|
||||
'models' => Category::query()->where('type', 'model')->where('is_active', true)->orderBy('name')->limit(8)->get(),
|
||||
'news' => Category::query()->where('type', 'news')->where('is_active', true)->orderBy('name')->limit(8)->get(),
|
||||
'guides' => Category::query()->where('type', 'guide')->where('is_active', true)->orderBy('name')->limit(8)->get(),
|
||||
],
|
||||
];
|
||||
});
|
||||
|
||||
return view('public.home', $payload);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user