Game.php 966 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use App\Models\GameplayRule;
  4. use Illuminate\Validation\ValidationException;
  5. use Exception;
  6. class Game extends BaseController
  7. {
  8. /**
  9. * @api {get} /game/rule 玩法规则
  10. */
  11. function rule()
  12. {
  13. try {
  14. request()->validate([
  15. 'page' => ['nullable', 'integer', 'min:1'],
  16. 'limit' => ['nullable', 'integer', 'min:1']
  17. ]);
  18. $page = request()->input('page', 1);
  19. $limit = request()->input('limit', 10);
  20. $list = GameplayRule::forPage($page, $limit)
  21. ->orderBy('groups')
  22. ->orderByDesc('created_at')
  23. ->get();
  24. } catch (ValidationException $e) {
  25. return $this->error($e->validator->errors()->first());
  26. } catch (Exception $e) {
  27. return $this->error($e->getMessage());
  28. }
  29. return $this->success($list);
  30. }
  31. }