ProgressController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\ProgressChapter;
  5. class ProgressController extends Controller
  6. {
  7. /**
  8. * Display a listing of the resource.
  9. * @return \Illuminate\Http\Response
  10. */
  11. public function index(Request $request)
  12. {
  13. //
  14. switch ($request->input('view')) {
  15. case 'channel':
  16. $table = ProgressChapter::whereIn('channel_id', explode('_', $request->get('channels', '')));
  17. break;
  18. default:
  19. return $this->error('invalid view', 400, 400);
  20. break;
  21. }
  22. if ($request->has('lang')) {
  23. $table = $table->where('lang', $request->get('lang'));
  24. }
  25. $count = $table->count();
  26. $table = $table->orderBy(
  27. $request->input('order', 'completed_at'),
  28. $request->input('dir', 'desc')
  29. );
  30. $table = $table->skip($request->input("offset", 0))
  31. ->take($request->input('limit', 10));
  32. $result = $table->get();
  33. return $this->ok(
  34. [
  35. "rows" => $result->toArray(),
  36. "total" => $count,
  37. ]
  38. );
  39. }
  40. /**
  41. * Store a newly created resource in storage.
  42. */
  43. public function store(Request $request)
  44. {
  45. //
  46. }
  47. /**
  48. * Display the specified resource.
  49. */
  50. public function show(string $id)
  51. {
  52. //
  53. }
  54. /**
  55. * Update the specified resource in storage.
  56. */
  57. public function update(Request $request, string $id)
  58. {
  59. //
  60. }
  61. /**
  62. * Remove the specified resource from storage.
  63. */
  64. public function destroy(string $id)
  65. {
  66. //
  67. }
  68. }