<button id="delAll">批量删除</button>
//给按钮一个id属性
<input type="checkbox" name="check" checkid="{{$v->id}}">
//给input设置一个自定义的id
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
//引入外部jQuery连接
$("#delAll").click(function () {
var _this = $(this)
var arr =[]
var delall = $("input[name='check']:checked").each(function (item) { //把input里选中的checkbox遍历到数组里
arr.push($(this).attr('checkid'))
})
var id =arr
$.get('game_delall',{id:id},function (res) { //jQuery.ajax第一个值是提交的地址,第二个值是要传过去的值,第三个是自定义的方法,预期返回格式默认是json
if(res.status==200){
delall.parent().parent().remove()
}else{
alert('请勾选要删除的内容')
}
},'json')
})
public function delall(Request $request){
$id = $request['id'];
$data = Game::delall($id);
if($data){
return json_encode(['status'=>200,'info'=>'删除成功','data'=>$data]);
}else{
return json_encode(['status'=>404,'info'=>'删除失败','data'=>'']);
}
}
//控制层
public static function delall($id){
return self::destroy($id);
}
//模型层