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

批量删除商品


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

php
public function deleteAll()
{
    $param = $this->request->param('ids');
    return showSuccess($this->M->where('id','in',$param)->delete());
}

模型 app/model/Goods.php

php
// 删除之后
   public static function onAfterDelete($goods){
       // 删除对应的goods_skus_card
       $goods->goodsSkusCard->each(function($v){
           $v->delete();
       });
   }

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

php
// 验证规则
protected $rule = [
    ...
    'ids'=>'require|array'
    ...
];

protected $scene = [
    ...
    'deleteAll'=>['ids']
];

路由 router/admin.php

php
Route::post('goods/delete_all','admin.goods/deleteAll');