VocabularyController.php 2.2 KB

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