lip 2 недель назад
Родитель
Сommit
b4c1f8913b
1 измененных файлов с 36 добавлено и 0 удалено
  1. 36 0
      app/Http/Controllers/api/Game.php

+ 36 - 0
app/Http/Controllers/api/Game.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace App\Http\Controllers\api;
+
+use App\Models\GameplayRule;
+use Illuminate\Validation\ValidationException;
+use Exception;
+
+class Game extends BaseController
+{
+    /**
+     * @api {get} /game/rule 玩法规则
+     */
+    function rule()
+    {
+        try {
+            request()->validate([
+                'page' => ['nullable', 'integer', 'min:1'],
+                'limit' => ['nullable', 'integer', 'min:1']
+            ]);
+            $page = request()->input('page', 1);
+            $limit = request()->input('limit', 10);
+            $list = GameplayRule::forPage($page, $limit)
+                ->orderBy('groups')
+                ->orderByDesc('created_at')
+                ->get();
+            
+        } catch (ValidationException $e) {
+            return $this->error($e->validator->errors()->first());
+        } catch (Exception $e) {
+            return $this->error($e->getMessage());
+        }
+        return $this->success($list);
+    }
+
+}