init
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

This commit is contained in:
jiangdong.cheng
2026-02-11 17:28:36 +08:00
parent dcb82557c7
commit aa16c9f8c2
162 changed files with 22333 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Site;
use App\Http\Controllers\Controller;
use App\Models\AiModel;
use App\Models\Category;
use App\Models\Guide;
use App\Models\Tool;
use App\Support\MarkdownRenderer;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
class GuideController extends Controller
{
public function __construct(
private readonly MarkdownRenderer $markdownRenderer,
) {
}
public function index(Request $request): View
{
$builder = Guide::query()->published()->with('category');
if ($request->filled('q')) {
$builder->whereFullText(['title', 'excerpt', 'body'], (string) $request->string('q'));
}
if ($request->filled('difficulty')) {
$builder->where('difficulty', (string) $request->string('difficulty'));
}
return view('public.guides.index', [
'items' => $builder->latest('published_at')->paginate(15)->withQueryString(),
'categories' => Category::query()->where('type', 'guide')->where('is_active', true)->orderBy('name')->get(),
'filters' => $request->only(['q', 'difficulty']),
'sidebarTools' => Tool::published()->latest('published_at')->limit(6)->get(),
'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(),
]);
}
public function byTopic(string $slug, Request $request): View
{
$request->merge(['difficulty' => $slug]);
return $this->index($request);
}
public function show(string $slug): View
{
/** @var Guide $guide */
$guide = Guide::query()
->published()
->with('category')
->where('slug', $slug)
->firstOrFail();
return view('public.guides.show', [
'item' => $guide,
'bodyHtml' => $this->markdownRenderer->render($guide->body),
]);
}
}