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.

81 lines
1.9 KiB

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