published()->with('category'); if ($request->filled('q')) { $builder->whereFullText(['title', 'excerpt', 'body'], (string) $request->string('q')); } if ($request->filled('category')) { $builder->whereHas('category', function ($query) use ($request): void { $query->where('slug', (string) $request->string('category')); }); } $categories = Category::query() ->where('type', 'news') ->where('is_active', true) ->withCount([ 'articles as published_articles_count' => fn (Builder $query): Builder => $query->published(), ]) ->orderByDesc('published_articles_count') ->orderBy('name') ->get(); $newsStats = [ 'total' => Article::query()->published()->count(), 'today' => Article::query()->published()->whereDate('published_at', today())->count(), 'high_source' => Article::query()->published()->where('source_level', 'high')->count(), 'updated_7d' => Article::query()->published()->where('updated_at', '>=', now()->subDays(7))->count(), ]; return view('public.news.index', [ 'items' => $builder->latest('published_at')->paginate(15)->withQueryString(), 'categories' => $categories, 'newsStats' => $newsStats, 'filters' => $request->only(['q', 'category']), 'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(), 'sidebarGuides' => Guide::published()->latest('published_at')->limit(6)->get(), ]); } public function show(string $slug): View { /** @var Article $article */ $article = Article::query() ->published() ->with(['category', 'source']) ->where('slug', $slug) ->firstOrFail(); return view('public.news.show', [ 'item' => $article, 'bodyHtml' => $this->markdownRenderer->render($article->body), 'showRiskNotice' => $this->containsRiskKeyword($article->title.' '.$article->body), 'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(), 'sidebarGuides' => Guide::published()->latest('published_at')->limit(6)->get(), ]); } private function containsRiskKeyword(string $text): bool { return str_contains($text, '医疗') || str_contains($text, '法律') || str_contains($text, '投资'); } }