VocabularyController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Cache;
  5. use App\Models\Vocabulary;
  6. use App\Http\Resources\VocabularyResource;
  7. class VocabularyController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index(Request $request)
  15. {
  16. //
  17. switch ($request->get("view")) {
  18. case 'key':
  19. $key = $request->get("key");
  20. $result = Cache::remember(
  21. "/dict_vocabulary/{$key}",
  22. config('mint.cache.expire'),
  23. function () use ($key) {
  24. $query = Vocabulary::where('word', 'like', $key . "%")
  25. ->orWhere('word_en', 'like', $key . "%")
  26. ->orderBy('strlen')
  27. ->orderBy('word')
  28. ->take(50);
  29. return $query->get();
  30. }
  31. );
  32. return $this->ok(['rows' => VocabularyResource::collection($result), 'count' => count($result)]);
  33. break;
  34. }
  35. }
  36. /**
  37. * Store a newly created resource in storage.
  38. *
  39. * @param \Illuminate\Http\Request $request
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function store(Request $request)
  43. {
  44. //
  45. }
  46. /**
  47. * Display the specified resource.
  48. *
  49. * @param \App\Models\Vocabulary $vocabulary
  50. * @return \Illuminate\Http\Response
  51. */
  52. public function show(Vocabulary $vocabulary)
  53. {
  54. //
  55. }
  56. /**
  57. * Update the specified resource in storage.
  58. *
  59. * @param \Illuminate\Http\Request $request
  60. * @param \App\Models\Vocabulary $vocabulary
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function update(Request $request, Vocabulary $vocabulary)
  64. {
  65. //
  66. }
  67. /**
  68. * Remove the specified resource from storage.
  69. *
  70. * @param \App\Models\Vocabulary $vocabulary
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function destroy(Vocabulary $vocabulary)
  74. {
  75. //
  76. }
  77. }