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',
);
protected $updateChildrenFields = 'status';
protected $updateChildrenFields = ['status'];
const LIST_TYPE = 1; // 列表
const PAGE_TYPE = 2; // 单页

View File

@ -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('分类名称重复,请重新填写');
}
}
}