ArticleController.php 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. $subscribe = auth()->user()->subscribe;
  14. return view('user.knowledge', [
  15. 'subType' => $nodeService->getActiveNodeTypes(),
  16. 'subUrl' => route('sub', $subscribe->code),
  17. 'subStatus' => $subscribe->status,
  18. 'subMsg' => $subscribe->ban_desc,
  19. 'knowledge' => Article::type(1)->lang()->orderByDesc('sort')->latest()->get()->groupBy('category'),
  20. ]);
  21. }
  22. public function show(Article $article): JsonResponse
  23. { // 公告详情
  24. $articleService = new ArticleService($article);
  25. return response()->json(['title' => $article->title, 'content' => $articleService->getContent()]);
  26. }
  27. }