init
This commit is contained in:
77
app/Http/Controllers/Site/ModelController.php
Normal file
77
app/Http/Controllers/Site/ModelController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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 Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModelController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$builder = AiModel::query()->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'));
|
||||
}
|
||||
|
||||
return view('public.models.index', [
|
||||
'items' => $builder->orderByDesc('total_score')->paginate(18)->withQueryString(),
|
||||
'categories' => Category::query()->where('type', 'model')->where('is_active', true)->orderBy('name')->get(),
|
||||
'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, '投资');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user