Skip to content
关注公众号,获取新课通知

删除单个商品


控制器 app/controller/admin/Goods.php

php
public function delete($id)
{
    return showSuccess($this->request->Model->delete());
}

模型 app/model/Goods.php

php
// 商品规格卡片
   public function goodsSkusCard(){
       return $this->hasMany('GoodsSkusCard')->order([
       	'order'=>'ASC'
       ]);
   }
// 删除之后
   public static function onAfterDelete($goods){
       // 删除对应的goods_skus_card
       $goods->goodsSkusCard->each(function($v){
           $v->delete();
       });
   }

验证器 app/validate/admin/Goods.php

php
// 验证规则
protected $rule = [
    ...
    'id'=>'require|integer|>:0|isExist:Goods',
    ...
];

protected $scene = [
    ...
    'delete'=>['id'],
];

路由 router/admin.php

php
Route::post('goods/:id/delete','admin.goods/delete');