1、删除数据 delete
delete 方法返回影响数据的条数,没有删除返回 0
public function index(){
# 根据条件删除数据
$delete = Db::table('shop_goods')->where('id',1)->delete();
print_r($delete);
# 删除主键为2的数据
$delete = Db::table('shop_goods')->delete(2);
print_r($delete);
# 删除整表数据
$delete = Db::table('shop_goods')->delete(true);
print_r($delete);
}
2、软删除 useSoftDelete
业务数据不建议真实删除数据,TP系统提供了软删除机制
public function index(){
# 软删除
$delete = Db::table('shop_goods')->useSoftDelete('status',3)->delete();
print_r($delete);
}
文章来自 www.dg-haiyue.cn