VocabularyController.php 2.3 KB

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