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.

76 lines
1.7 KiB

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