|
@@ -92,21 +92,29 @@ class Keyboard extends Controller
|
|
|
public function store()
|
|
public function store()
|
|
|
{
|
|
{
|
|
|
// try {
|
|
// 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) {
|
|
// } catch (ValidationException $e) {
|
|
|
// return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
|
|
// return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
|
|
|
// } catch (Exception $e) {
|
|
// } catch (Exception $e) {
|