删除属性组时同时删除描述

删除属性组时检查是否有属性在使用
删除属性时同时删除描述
This commit is contained in:
TL 2023-01-13 09:49:48 +08:00 committed by Edward Yang
parent 7443f9d74c
commit 216bf84a2c
4 changed files with 7 additions and 0 deletions

View File

@ -69,6 +69,10 @@ class AttributeGroupRepo
public static function delete($id)
{
$group = AttributeGroup::query()->findOrFail($id);
if ($group->attributes->count()) {
throw New \Exception(trans('admin/attribute_groups.error_cannot_delete_attribute_used', ['attributes' => implode(', ', $group->attributes->pluck('id')->toArray())]));
}
$group->descriptions()->delete();
$group->delete();
}
}

View File

@ -108,6 +108,7 @@ class AttributeRepo
public static function delete($id)
{
$attribute = Attribute::query()->findOrFail($id);
$attribute->descriptions()->delete();
$attribute->values()->delete();
$attribute->delete();
}

View File

@ -12,4 +12,5 @@
return [
'index' => 'Attribute group',
'create_at_groups' => 'Create attribute group',
'error_cannot_delete_attribute_used' => 'Attribute Group used by attribute (ID: attributes), can not be deleted!'
];

View File

@ -12,4 +12,5 @@
return [
'index' => '属性组',
'create_at_groups' => '创建属性组',
'error_cannot_delete_attribute_used' => '属性组不能删除由于该属性组被属性属性ID: :attributes使用'
];