From d6e5fa091adcfb6b6b9ce61f5987064080f5df77 Mon Sep 17 00:00:00 2001 From: JaguarJack <82664165@qq.com> Date: Mon, 24 May 2021 21:17:27 +0800 Subject: [PATCH] update cms category --- catch/cms/model/Category.php | 2 +- catch/cms/model/events/CategoryEvent.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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('分类名称重复,请重新填写'); + } } }