refactor: 视频分类删除检查分类下是否存在视频

This commit is contained in:
2025-02-21 09:40:50 +08:00
parent 564177918d
commit dbb2cc07de
2 changed files with 11 additions and 0 deletions

View File

@@ -149,6 +149,11 @@ class VideoCategory
return error('请确认操作对象是否存在');
}
// 检查该分类下是否存在视频
if ($category->video()->count()) {
return error('该分类下存在视频,请先删除视频');
}
if (!$category->delete()) {
return error('操作失败');
}

View File

@@ -11,6 +11,12 @@ use app\common\model\VideoCategoryBaseModel;
*/
class VideoCategoryModel extends VideoCategoryBaseModel
{
// 关联视频模型
public function video()
{
return $this->hasMany(VideoModel::class, 'category_id', 'id');
}
// 分类名称搜索
public function searchNameAttr($query, $value)
{