diff --git a/catch/cms/model/Category.php b/catch/cms/model/Category.php index 139b04a..e351295 100644 --- a/catch/cms/model/Category.php +++ b/catch/cms/model/Category.php @@ -61,7 +61,7 @@ class Category extends BaseModel 'deleted_at', ); - protected $updateChildrenFields = 'status'; + protected $updateChildrenFields = ['status']; const LIST_TYPE = 1; // 列表 const PAGE_TYPE = 2; // 单页 diff --git a/catch/cms/model/events/CategoryEvent.php b/catch/cms/model/events/CategoryEvent.php index 0bd931b..96f52de 100644 --- a/catch/cms/model/events/CategoryEvent.php +++ b/catch/cms/model/events/CategoryEvent.php @@ -48,10 +48,14 @@ trait CategoryEvent */ public static function onBeforeUpdate(\think\Model $category) { - $where = $category->getWhere(); + $data = $category->getData(); - if (self::where('name', $category->getData('name'))->where('id', '<>', $where['id'])->find()) { - throw new FailedException('分类名称重复,请重新填写'); + if (isset($data['name'])) { + $where = $category->getWhere(); + + if (self::where('name', $category->getData('name'))->where('id', '<>', $where['id'])->find()) { + throw new FailedException('分类名称重复,请重新填写'); + } } }