update cms category

This commit is contained in:
JaguarJack 2021-05-24 21:17:27 +08:00
parent bcfb184618
commit d6e5fa091a
2 changed files with 8 additions and 4 deletions

View File

@ -61,7 +61,7 @@ class Category extends BaseModel
'deleted_at', 'deleted_at',
); );
protected $updateChildrenFields = 'status'; protected $updateChildrenFields = ['status'];
const LIST_TYPE = 1; // 列表 const LIST_TYPE = 1; // 列表
const PAGE_TYPE = 2; // 单页 const PAGE_TYPE = 2; // 单页

View File

@ -48,12 +48,16 @@ trait CategoryEvent
*/ */
public static function onBeforeUpdate(\think\Model $category) public static function onBeforeUpdate(\think\Model $category)
{ {
$data = $category->getData();
if (isset($data['name'])) {
$where = $category->getWhere(); $where = $category->getWhere();
if (self::where('name', $category->getData('name'))->where('id', '<>', $where['id'])->find()) { if (self::where('name', $category->getData('name'))->where('id', '<>', $where['id'])->find()) {
throw new FailedException('分类名称重复,请重新填写'); throw new FailedException('分类名称重复,请重新填写');
} }
} }
}
/** /**
* 删除前 * 删除前