On this page
删除商品类型
控制器 app/controller/admin/GoodsType.php
php
public function delete($id)
{
$sku = $this->request->Model;
return showSuccess($sku->delete());
}
模型 app/model/GoodsType.php
php
// 删除后操作
public static function onAfterDelete($goodsType){
// 删除该类型下所有类型属性
$goodsType->goodsTypeValues->each(function($v){
$v->delete();
});
// 删除与sku的关联
SkusGoodsType::where('goods_type_id',$goodsType->id)->delete();
}
验证器 app/validate/admin/GoodsType.php
php
// 验证规则
protected $rule = [
...
'id'=>'require|integer|>:0|isExist:GoodsType',
...
];
protected $scene = [
...
'delete'=>['id'],
];
路由 router/admin.php
php
Route::post('goods_type/:id/delete','admin.GoodsType/delete');