NoticeController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Models\Notice;
  4. use Illuminate\Http\Request;
  5. use App\Http\Requests;
  6. use Illuminate\Support\Facades\Config;
  7. use Mockery\Matcher\Not;
  8. class NoticeController extends AdminController
  9. {
  10. /*权限验证规则*/
  11. protected $validateRules = [
  12. 'subject' => 'required|max:255',
  13. 'url' => 'required|max:255',
  14. 'style' => 'sometimes|max:255'
  15. ];
  16. /**
  17. * 显示公告列表
  18. *
  19. * @return \Illuminate\Http\Response
  20. */
  21. public function index(Request $request)
  22. {
  23. $word = $request->input("word",'');
  24. $notices = Notice::where('subject','like',"%$word%")->orderBy('updated_at','DESC')->paginate(Config::get('tipask.admin.page_size'));
  25. return view('admin.notice.index')->with('notices',$notices)->with('word',$word);
  26. }
  27. /**
  28. * Show the form for creating a new resource.
  29. *
  30. * @return \Illuminate\Http\Response
  31. */
  32. public function create()
  33. {
  34. return view('admin.notice.create');
  35. }
  36. /**
  37. * 保存添加的公告信息
  38. *
  39. * @param \Illuminate\Http\Request $request
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function store(Request $request)
  43. {
  44. $request->flash();
  45. $this->validate($request,$this->validateRules);
  46. Notice::create($request->all());
  47. return $this->success(route('admin.notice.index'),'公告添加成功');
  48. }
  49. /**
  50. * Display the specified resource.
  51. *
  52. * @param int $id
  53. * @return \Illuminate\Http\Response
  54. */
  55. public function show($id)
  56. {
  57. //
  58. }
  59. /**
  60. * Show the form for editing the specified resource.
  61. *
  62. * @param int $id
  63. * @return \Illuminate\Http\Response
  64. */
  65. public function edit($id)
  66. {
  67. $notice = Notice::find($id);
  68. if(!$notice){
  69. return $this->error(route('admin.notice.index'),'公告不存在,请核实');
  70. }
  71. return view('admin.notice.edit')->with('notice',$notice);
  72. }
  73. /**
  74. * Update the specified resource in storage.
  75. *
  76. * @param \Illuminate\Http\Request $request
  77. * @param int $id
  78. * @return \Illuminate\Http\Response
  79. */
  80. public function update(Request $request, $id)
  81. {
  82. $request->flash();
  83. $notice = Notice::find($id);
  84. if(!$notice){
  85. return $this->error(route('admin.notice.index'),'公告不存在,请核实');
  86. }
  87. $this->validate($request,$this->validateRules);
  88. $notice->subject = $request->input('subject');
  89. $notice->style = $request->input('style','');
  90. $notice->url = $request->input('url');
  91. $notice->status = $request->input('status');
  92. $notice->save();
  93. return $this->success(route('admin.notice.index'),'公告修改成功');
  94. }
  95. /**
  96. * 删除公告
  97. *
  98. * @param int $id
  99. * @return \Illuminate\Http\Response
  100. */
  101. public function destroy(Request $request)
  102. {
  103. Notice::destroy($request->input('ids'));
  104. return $this->success(route('admin.notice.index'),'公告删除成功');
  105. }
  106. }