You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. class MenuController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index()
  12. {
  13. $posts = parent::pageList('menu');
  14. $data['posts'] = $posts;
  15. return view('admin.menu.index', $data);
  16. }
  17. public function add()
  18. {
  19. $data['menu'] = category_tree(get_category('menu',0));
  20. return view('admin.menu.add', $data);
  21. }
  22. public function doadd()
  23. {
  24. unset($_POST["_token"]);
  25. if(DB::table('menu')->insert($_POST))
  26. {
  27. success_jump('添加成功!', route('admin_menu'));
  28. }
  29. else
  30. {
  31. error_jump('添加失败!请修改后重新添加');
  32. }
  33. }
  34. public function edit()
  35. {
  36. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  37. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  38. $data['id'] = $id;
  39. $data['post'] = object_to_array(DB::table('menu')->where('id', $id)->first(), 1);
  40. $data['menu'] = category_tree(get_category('menu',0));
  41. return view('admin.menu.edit', $data);
  42. }
  43. public function doedit()
  44. {
  45. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  46. unset($_POST["_token"]);
  47. if(DB::table('menu')->where('id', $id)->update($_POST))
  48. {
  49. success_jump('修改成功!', route('admin_menu'));
  50. }
  51. else
  52. {
  53. error_jump('修改失败!');
  54. }
  55. }
  56. public function del()
  57. {
  58. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
  59. if(DB::table('menu')->whereIn("id", explode(',', $id))->delete())
  60. {
  61. success_jump('删除成功');
  62. }
  63. else
  64. {
  65. error_jump('删除失败!请重新提交');
  66. }
  67. }
  68. }