2
0

SentSimController.php 2.4 KB

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