laravel之批量删除

表单

<center>
    <a href="{{URL('add')}}"><button style="width:80px;">+button>a>
    <table border="1">
        <tr>
            <td><input type="checkbox" name="">td>
            <td>名称td>
            <td>价格td>
            <td>操作td>
        tr>
        @foreach($users as $k => $v)
        <tr>
            <tr>
                <td><input type="checkbox" name="box" value="{{$v->g_id}}">td>
                <td  pid="{{$v->g_id}}"><span class="name">{{$v->g_name}}span>td>
                <td pid="{{$v->g_id}}"><span class="price">{{$v->g_price}}span>td>
                <td><a href="del?g_id={{$v->g_id}}">删除a>td>
            tr>
        tr>
        @endforeach
    table>
    <button class="pl">批量删除button>
center>

js
<script src="style/js/jquery-1.7.2.min.js">script>

<script>
    //批量删除
    $(".pl").click(function(){
        var  box = $("input[name='box']");
        length =box.length;
        //alert(length);
        var str ="";
        for(var i=0;i<length;i++){
            if(box[i].checked==true){
                str =str+","+box[i].value;
            }
        }
        str= str.substr(1)
        //alert(str)
        location.href="del2?id="+str;
    })
script>

控制器
//删除移除
public function  del2(){
    $g_id = input::get('id');
    $str = explode(",",$g_id);
    foreach($str as $v){
        DB::table('goods')->where('g_id',"=","$v")->delete();
    }
    return  redirect("index");
}

你可能感兴趣的:(php)