2
0

SentSimController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. ->where('sim',">",0.7)
  29. ->orderBy('sim','desc');
  30. break;
  31. }
  32. $count = $table->count();
  33. $table->skip($request->get("offset",0))->take($request->get('limit',200));
  34. $result = $table->get();
  35. if($result){
  36. return $this->ok(["rows"=>SentSimResource::collection($result),"count"=>$count]);
  37. }else{
  38. return $this->error("no data");
  39. }
  40. }
  41. /**
  42. * Show the form for creating a new resource.
  43. *
  44. * @return \Illuminate\Http\Response
  45. */
  46. public function create()
  47. {
  48. //
  49. }
  50. /**
  51. * Store a newly created resource in storage.
  52. *
  53. * @param \Illuminate\Http\Request $request
  54. * @return \Illuminate\Http\Response
  55. */
  56. public function store(Request $request)
  57. {
  58. //
  59. }
  60. /**
  61. * Display the specified resource.
  62. *
  63. * @param \App\Models\SentSim $sentSim
  64. * @return \Illuminate\Http\Response
  65. */
  66. public function show(SentSim $sentSim)
  67. {
  68. //
  69. }
  70. /**
  71. * Show the form for editing the specified resource.
  72. *
  73. * @param \App\Models\SentSim $sentSim
  74. * @return \Illuminate\Http\Response
  75. */
  76. public function edit(SentSim $sentSim)
  77. {
  78. //
  79. }
  80. /**
  81. * Update the specified resource in storage.
  82. *
  83. * @param \Illuminate\Http\Request $request
  84. * @param \App\Models\SentSim $sentSim
  85. * @return \Illuminate\Http\Response
  86. */
  87. public function update(Request $request, SentSim $sentSim)
  88. {
  89. //
  90. }
  91. /**
  92. * Remove the specified resource from storage.
  93. *
  94. * @param \App\Models\SentSim $sentSim
  95. * @return \Illuminate\Http\Response
  96. */
  97. public function destroy(SentSim $sentSim)
  98. {
  99. //
  100. }
  101. }