1
0

ArticleController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Controllers\User;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Article;
  5. use App\Models\Node;
  6. use App\Services\ArticleService;
  7. use Illuminate\Http\JsonResponse;
  8. class ArticleController extends Controller
  9. {
  10. public function index()
  11. { // 帮助中心
  12. $data = [];
  13. if (Node::whereType(0)->whereStatus(1)->exists()) {
  14. $data[] = 'ss';
  15. }
  16. if (Node::whereIn('type', [1, 4])->whereStatus(1)->exists()) {
  17. $data[] = 'ssr';
  18. }
  19. if (Node::whereType(2)->whereStatus(1)->exists()) {
  20. $data[] = 'v2';
  21. }
  22. if (Node::whereType(3)->whereStatus(1)->exists()) {
  23. $data[] = 'trojan';
  24. }
  25. $subscribe = auth()->user()->subscribe;
  26. return view('user.knowledge', [
  27. 'subType' => $data,
  28. 'subUrl' => route('sub', $subscribe->code),
  29. 'subStatus' => $subscribe->status,
  30. 'subMsg' => $subscribe->ban_desc,
  31. 'knowledges' => Article::type(1)->lang()->orderByDesc('sort')->latest()->get()->groupBy('category'),
  32. ]);
  33. }
  34. public function show(Article $article): JsonResponse
  35. { // 公告详情
  36. $articleService = new ArticleService($article);
  37. return response()->json(['title' => $article->title, 'content' => $articleService->getContent()]);
  38. }
  39. }