VocabularyController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. 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("/dict_vocabulary/{$key}",60,function() use($key){
  21. return Vocabulary::where('word_en','like',$key."%")->take(10)->get();
  22. });
  23. if($result){
  24. return $this->ok(['rows'=>VocabularyResource::collection($result),'count'=>count($result)]);
  25. }else{
  26. return $this->error();
  27. }
  28. break;
  29. }
  30. }
  31. /**
  32. * Store a newly created resource in storage.
  33. *
  34. * @param \Illuminate\Http\Request $request
  35. * @return \Illuminate\Http\Response
  36. */
  37. public function store(Request $request)
  38. {
  39. //
  40. }
  41. /**
  42. * Display the specified resource.
  43. *
  44. * @param \App\Models\Vocabulary $vocabulary
  45. * @return \Illuminate\Http\Response
  46. */
  47. public function show(Vocabulary $vocabulary)
  48. {
  49. //
  50. }
  51. /**
  52. * Update the specified resource in storage.
  53. *
  54. * @param \Illuminate\Http\Request $request
  55. * @param \App\Models\Vocabulary $vocabulary
  56. * @return \Illuminate\Http\Response
  57. */
  58. public function update(Request $request, Vocabulary $vocabulary)
  59. {
  60. //
  61. }
  62. /**
  63. * Remove the specified resource from storage.
  64. *
  65. * @param \App\Models\Vocabulary $vocabulary
  66. * @return \Illuminate\Http\Response
  67. */
  68. public function destroy(Vocabulary $vocabulary)
  69. {
  70. //
  71. }
  72. }