Files
ai-web/app/Http/Controllers/Public/HomeController.php
jiangdong.cheng aa16c9f8c2
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
init
2026-02-11 17:28:36 +08:00

37 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Public;
use App\Http\Controllers\Controller;
use App\Models\AiModel;
use App\Models\Article;
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', now()->addMinutes(10), function (): array {
return [
'stats' => [
'tools' => Tool::published()->count(),
'models' => AiModel::published()->count(),
'articles' => Article::published()->count(),
'guides' => Guide::published()->count(),
],
'latestTools' => Tool::published()->latest('published_at')->limit(8)->get(),
'latestModels' => AiModel::published()->orderByDesc('total_score')->limit(8)->get(),
'latestArticles' => Article::published()->latest('published_at')->limit(6)->get(),
'latestGuides' => Guide::published()->latest('published_at')->limit(6)->get(),
];
});
return view('public.home', $payload);
}
}