页面展示
<button type="button" class="btn-danger" id="batchDel">批量删除</button>
<th><input id="checkAll" type="checkbox"></th>
<td><input class="checkOne" type="checkbox" value="{$v.id}"></td>
<script>
$('#checkAll').click(function () {
$('.checkOne').prop('checked',$(this).prop('checked'))
})
$('#batchDel').click(function () {
var id = [];
$('input:checkbox').each(function (i) {
id[i] = $(this).val();
});
$.ajax({
url:'articleDels',
type:'get',
dataType:'json',
data:{
id:id,
},
success:function (res) {
if (res.code==200){
location.href='list'
}
}
})
});
</script>
控制器
public function articleDels(Request $request)
{
$id=$request->param('id');
$class=new listModel();
$res=$class->delAll($id);
return json(['code'=>200,'msg'=>'成功','data'=>[]]);
}
模型
public function delAll($id)
{
return self::destroy($id);
}