码迷,mamicode.com
首页 > 其他好文 > 详细

状态即点即改与删除

时间:2021-01-29 12:18:41      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:str   bsp   where   修改   put   stat   ret   load()   ken   

 即点即改:

1  @if($v->fang_status==1)
2               <span class="label label-info radius zhuangtaiUp" id="zhuangtaiUp" href="{{route(‘admin.zhuangtaiUp‘,[‘id‘=>$v->id])}}" where="1">展示{{$v->id}}</span>
3                 @else
4                <span class="label label-success radius zhuangtaiUp" id="zhuangtaiUp" href="{{route(‘admin.zhuangtaiUp‘,[‘id‘=>$v->id])}}" where="0">隐藏{{$v->id}}</span>
5  @endif

  <span class="label label-danger radius" href="{{route(‘admin.book.destroy‘,$v[‘id‘])}}">删除</span>
<script type="text/javascript">
$(‘.zhuangtaiUp‘).click(function () {
            let that=this
            let url=$(this).attr(‘href‘)
            let where=$(this).attr(‘where‘)

            //发送ajax
            $.ajax({
                url:url,
                type:‘get‘,
                data:{
                    _token:"{{csrf_token()}}",
                    where:where
                },
                dataType: "json",
                success: function(msg){
                    if (msg.code==200){
                        location.reload()
                    }else {
                        alert(‘修改失败‘)
                    }
                }
            })
    })
  
  //删除
    $(".label-danger").click(function () {
        let that=this
        let url=$(this).attr(‘href‘);
       $.ajax({
           url:url,
           type:"DELETE",
           data:{
               _token:"{{csrf_token()}}"
           },
           dataType: "json",
           success: function(msg){
               alert( "Data Saved: " + msg );
           }
       })

    })

</script>

 

 

控制器层

//删除
  
public function destroy(Book $Book)
    {
        //
       $fang->delete();
        return [‘code‘=>200,‘msg‘=>‘删除成功‘];

    }


//状态
 public function zhuangtaiUp(Request $request){
        //过滤
        $id=$request->input(‘id‘);
        if (!is_numeric($id)){
            return [‘code‘=>500,‘msg‘=>‘参数id不正确‘];
        }
        $data=Book::where(‘id‘,$id)->first();
        $zhuangtaiUp=$data[‘book_status‘];
        if ($zhuangtaiUp==1){
            Book::where(‘id‘,$id)->update([‘book_status‘=>"0"]);
            return [‘code‘=>200,‘msg‘=>‘success‘,‘data‘=>‘‘];
        }else{
           Book::where(‘id‘,$id)->update([‘book_status‘=>1]);
            return [‘code‘=>200,‘msg‘=>‘success‘,‘data‘=>‘‘];

        }

    }

 

状态即点即改与删除

标签:str   bsp   where   修改   put   stat   ret   load()   ken   

原文地址:https://www.cnblogs.com/cyxng/p/14342649.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!