🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ /** * 修改颜色 */ public function edit() { $id = input('post.id/d'); // 准备更新的数据 $data = $this->_postData(); // 避免新数据和其他数据名称重复 $isExists = self::where('name', $data['name']) ->where('id', '<>', $id) ->find(); if ($isExists !== null) { return res(203, '该颜色名称已存在'); } // 数据验证 try { validate('app\index\validate\DoorColor.edit')->check($data); } catch (\think\exception\ValidateException $e) { return res(201, $e->getError()); } // 执行更新 try { self::update($data, ['id' => $id]); } catch (\think\db\exception\PDOException $e) { return res(202, $e->getMessage()); } return res(200, '修改成功'); } ~~~