ArticleController.php 1005 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\Http\JsonResponse;
  8. class ArticleController extends Controller
  9. {
  10. public function index(NodeService $nodeService)
  11. { // 帮助中心
  12. $subscribe = auth()->user()->subscribe;
  13. return view('user.knowledge', [
  14. 'subType' => $nodeService->getActiveNodeTypes(),
  15. 'subUrl' => route('sub', $subscribe->code),
  16. 'subStatus' => $subscribe->status,
  17. 'subMsg' => $subscribe->ban_desc,
  18. 'knowledges' => 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. }