1.增加删除按钮
public function getBtnAttribute()
{
$id = $this->id;
return
"<a title='查看' href='javascript:;' onclick="."member_edit('查看','http://week2.1908a.com/index.php/show?id={$id}','4','','510')"." class='ml-5' style='text-decoration:none'><i class='Hui-iconfont'></i></a><a onclick='del($id)' class='$id'><button>删除</button></a>";
}
2.js前端
const _token="{{csrf_token()}}";
//详情展示
function member_edit(title,url,id,w,h){
layer_show(title,url,w,h);
}
//删除
function del(id){
layer.confirm('确认要删除吗?',function(){
$.ajax({
url:'{{url("del")}}',
data:{
id:id,
_token:_token
},
dataType:'json',
type:'delete',
success(obj){
if(obj.code==200){
$('.'+id).parents("tr").remove();
layer.msg('已删除!',{icon:1,time:1000});
}else {
layer.msg(e.msg,{icon:1,time:1000});
}
}
})
});
}
3.控制器调用模型层删除
public function destroy(Request $request)
{
$id=$request->input('id');
$result=CompanyModel::delData($id);
if(!$result){
return json_encode(['code'=>400,'msg'=>"删除失败"]);
}return json_encode(['code'=>200,'msg'=>"删除成功"]);
}