SentSimController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\SentSim;
  4. use App\Models\PaliSentence;
  5. use Illuminate\Http\Request;
  6. use App\Http\Resources\SentSimResource;
  7. class SentSimController 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 'sentence':
  19. $sentId = PaliSentence::where('book',$request->get('book'))
  20. ->where('paragraph',$request->get('paragraph'))
  21. ->where('word_begin',$request->get('start'))
  22. ->where('word_end',$request->get('end'))
  23. ->value('id');
  24. if(!$sentId){
  25. return $this->error("no sent");
  26. }
  27. $table = SentSim::where('sent1',$sentId)
  28. ->orderBy('sim','desc');
  29. break;
  30. }
  31. $table->where('sim','>=',$request->get('sim',0));
  32. $count = $table->count();
  33. $table->skip($request->get("offset",0))
  34. ->take($request->get('limit',20));
  35. $result = $table->get();
  36. if($result){
  37. return $this->ok(["rows"=>SentSimResource::collection($result),"count"=>$count]);
  38. }else{
  39. return $this->error("no data");
  40. }
  41. }
  42. /**
  43. * Show the form for creating a new resource.
  44. *
  45. * @return \Illuminate\Http\Response
  46. */
  47. public function create()
  48. {
  49. //
  50. }
  51. /**
  52. * Store a newly created resource in storage.
  53. *
  54. * @param \Illuminate\Http\Request $request
  55. * @return \Illuminate\Http\Response
  56. */
  57. public function store(Request $request)
  58. {
  59. //
  60. }
  61. /**
  62. * Display the specified resource.
  63. *
  64. * @param \App\Models\SentSim $sentSim
  65. * @return \Illuminate\Http\Response
  66. */
  67. public function show(SentSim $sentSim)
  68. {
  69. //
  70. }
  71. /**
  72. * Show the form for editing the specified resource.
  73. *
  74. * @param \App\Models\SentSim $sentSim
  75. * @return \Illuminate\Http\Response
  76. */
  77. public function edit(SentSim $sentSim)
  78. {
  79. //
  80. }
  81. /**
  82. * Update the specified resource in storage.
  83. *
  84. * @param \Illuminate\Http\Request $request
  85. * @param \App\Models\SentSim $sentSim
  86. * @return \Illuminate\Http\Response
  87. */
  88. public function update(Request $request, SentSim $sentSim)
  89. {
  90. //
  91. }
  92. /**
  93. * Remove the specified resource from storage.
  94. *
  95. * @param \App\Models\SentSim $sentSim
  96. * @return \Illuminate\Http\Response
  97. */
  98. public function destroy(SentSim $sentSim)
  99. {
  100. //
  101. }
  102. }