published()->with('category'); if ($request->filled('q')) { $builder->whereFullText(['name', 'summary', 'description'], (string) $request->string('q')); } if ($request->filled('modality')) { $builder->where('modality', (string) $request->string('modality')); } if ($request->filled('deployment')) { $builder->where('deployment_mode', (string) $request->string('deployment')); } $modalityCounts = AiModel::query() ->published() ->selectRaw('modality, COUNT(*) as aggregate') ->groupBy('modality') ->pluck('aggregate', 'modality'); $modalityOptions = [ ['value' => 'text', 'label' => '文本', 'count' => (int) ($modalityCounts['text'] ?? 0)], ['value' => 'multimodal', 'label' => '多模态', 'count' => (int) ($modalityCounts['multimodal'] ?? 0)], ['value' => 'image', 'label' => '图像', 'count' => (int) ($modalityCounts['image'] ?? 0)], ['value' => 'audio', 'label' => '音频', 'count' => (int) ($modalityCounts['audio'] ?? 0)], ]; $modelStats = [ 'total' => AiModel::query()->published()->count(), 'multimodal' => AiModel::query()->published()->where('modality', 'multimodal')->count(), 'api' => AiModel::query()->published()->where('deployment_mode', 'api')->count(), 'updated_7d' => AiModel::query()->published()->where('updated_at', '>=', now()->subDays(7))->count(), ]; return view('public.models.index', [ 'items' => $builder->orderByDesc('total_score')->paginate(18)->withQueryString(), 'modalityOptions' => $modalityOptions, 'modelStats' => $modelStats, 'filters' => $request->only(['q', 'modality', 'deployment']), 'sidebarTools' => \App\Models\Tool::published()->latest('published_at')->limit(6)->get(), 'sidebarNews' => Article::published()->latest('published_at')->limit(6)->get(), ]); } public function byUseCase(string $slug, Request $request): View { $request->merge(['modality' => $slug]); return $this->index($request); } public function show(string $slug): View { /** @var AiModel $model */ $model = AiModel::query() ->published() ->with(['category', 'source', 'alternative']) ->where('slug', $slug) ->firstOrFail(); $relatedModels = AiModel::query() ->published() ->whereKeyNot($model->id) ->when($model->modality !== null, fn (Builder $query): Builder => $query->where('modality', $model->modality)) ->orderByDesc('total_score') ->limit(6) ->get(); return view('public.models.show', [ 'item' => $model, 'relatedModels' => $relatedModels, 'showRiskNotice' => $this->containsRiskKeyword($model->summary.' '.$model->description), ]); } private function containsRiskKeyword(string $text): bool { return str_contains($text, '医疗') || str_contains($text, '法律') || str_contains($text, '投资'); } }