Ken 2 minggu lalu
induk
melakukan
849e992819
1 mengubah file dengan 20 tambahan dan 12 penghapusan
  1. 20 12
      app/Http/Controllers/admin/Keyboard.php

+ 20 - 12
app/Http/Controllers/admin/Keyboard.php

@@ -92,21 +92,29 @@ class Keyboard extends Controller
     public function store()
     {
         // try {
-            $params = request()->all();
 
-            $validator = [
-                // 'name' => 'required|string|max:50|alpha_dash',
-                // 'name' => 'required|string|max:50|alpha_dash|unique:keyboards,name',
-                'button' => 'required|nullable|string|max:100',
-                'reply' => 'required|nullable|string',
-            ];
+        $id = request()->input('id', null);
+        $validator = [
+            // 'name' => 'required|string|max:50|alpha_dash',
+            // 'name' => 'required|string|max:50|alpha_dash|unique:keyboards,name',
+//            'button' => 'required|nullable|string|max:100',
+            'id' => ['required', 'integer'],
+            'reply' => 'required|string',
+            'image' => ['nullable', 'url'],
+            'buttons' => ['required', 'array'],
+        ];
+        if (!$id) {
+            unset($validator['id']);
+            $validator['button'] = ['required', 'string', 'min:1', 'max:100'];
+        }
+
 
-            request()->validate($validator);
+        $params = request()->validate($validator);
 
-            $ret = KeyboardService::submit($params);
-            if ($ret['code'] == KeyboardService::NOT) {
-                return $this->error($ret['code'], $ret['msg']);
-            }
+        $ret = KeyboardService::submit($params);
+        if ($ret['code'] == KeyboardService::NOT) {
+            return $this->error($ret['code'], $ret['msg']);
+        }
         // } catch (ValidationException $e) {
         //     return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
         // } catch (Exception $e) {