ArticleController.php 996 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Http\Controllers\User;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Article;
  5. use App\Services\ArticleService;
  6. use App\Services\NodeService;
  7. use Illuminate\Contracts\View\View;
  8. use Illuminate\Http\JsonResponse;
  9. class ArticleController extends Controller
  10. {
  11. public function index(NodeService $nodeService): View
  12. { // 帮助中心
  13. $user = auth()->user();
  14. return view('user.knowledge', [
  15. 'subType' => $nodeService->getActiveNodeTypes(),
  16. 'subUrl' => $user->sub_url,
  17. 'subscribe' => $user->subscribe->only(['status', 'ban_desc']),
  18. 'knowledge' => Article::type(1)->lang()->orderByDesc('sort')->latest()->get()->groupBy('category'),
  19. ]);
  20. }
  21. public function show(Article $article): JsonResponse
  22. { // 公告详情
  23. $articleService = new ArticleService($article);
  24. return response()->json(['title' => $article->title, 'content' => $articleService->getContent()]);
  25. }
  26. }