ProgressController.php 1.7 KB

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