1 JS代码
function deleteInfo(id) { if(id) { var r=confirm('确定要删除吗'); if(r==true) { $.ajax({ url: "{{ URL('admin/announcements/delete/') }}", type: "POST", data:{id:id,_token:'{{csrf_token()}}'}, success: function(data){ if(data==1) { alert('删除成功'); location.href= "{{ URL('admin/announcements/')}}"; } else { alert('删除失败'); } }}); } } } </script>
2 路由规则
$router->post('announcements/delete', 'AnnouncementsController@delete');
3 控制器代码
public function delete(Request $request) { $res=0; $id=$request->input('id'); $announcement = Announcement::find($id); $result=$announcement->delete(); $result==true && $res=1; return $res; }