Files
Epicnabbo-Catalogus-Updated…/cms update/app/Http/Controllers/Articles/ArticleController.php
T
Remco b67e0ec2b9 🆙 Add fixed cms 🆙
2026-02-02 19:30:21 +01:00

51 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers\Articles;
use App\Http\Controllers\Controller;
use App\Models\Articles\WebsiteArticle;
use App\Services\Articles\ArticleService;
use App\Services\Articles\ReactionService;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ArticleController extends Controller
{
public function __construct(
private readonly ArticleService $articlesService,
private readonly ReactionService $reactionService,
) {}
public function index(): View
{
$articles = $this->articlesService->getArticles(true);
return view('community.articles', [
'articles' => $articles,
]);
}
public function show(WebsiteArticle $article): View
{
$reactions = $article->reactions()
->with('user:id,username')
->get();
return view('community.article', [
'article' => $article,
'otherArticles' => WebsiteArticle::whereNot('slug', $article->slug)->latest('id')->take(15)->get(),
'myReactions' => Auth::check() ? $reactions->where('user_id', Auth::id())->pluck('reaction') : [],
'articleReactions' => $reactions->groupBy('reaction', true),
]);
}
public function toggleReaction(WebsiteArticle $article, Request $request): JsonResponse
{
$response = $this->reactionService->toggleReaction($article, Auth::user(), $request);
return response()->json($response);
}
}