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.

77 lines
1.7 KiB

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