NoticeBoardController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Employee;
  7. use App\Models\NoticeBoard;
  8. use App\Models\NoticeSend;
  9. use App\User;
  10. use DB;
  11. class NoticeBoardController extends Controller
  12. {
  13. public function index()
  14. {
  15. $user_id = \Auth::user()->id;
  16. $data['title'] = "Notice Board";/*
  17. $data['notices'] = NoticeBoard::with('user')->orderBy('id','DESC')->get();*/
  18. $data['notices'] = DB::table('notice_boards')
  19. ->join('users', 'notice_boards.employee_id', '=', 'users.id')
  20. ->join('notice_sends', 'notice_boards.id', '=', 'notice_sends.notice_id')
  21. ->select('notice_boards.*', 'users.name')
  22. ->where('notice_sends.sendto_id',$user_id)
  23. ->orWhere('notice_sends.sendto_id', 'all')
  24. ->orderBy('id','DESC')
  25. ->get();
  26. return view('admin.notice_board/index',$data);
  27. }
  28. public function create()
  29. {
  30. $user_id = \Auth::user()->id;
  31. $data['title'] = "Notice Add";
  32. $data['employee'] = User::where('employee_id','!=', "")->orWhere('utype',1)->orderBy('id','DESC')->get();
  33. return view('admin.notice_board/add',$data);
  34. }
  35. public function store(Request $request)
  36. {
  37. $user_id = \Auth::user()->id;
  38. $notice = new NoticeBoard;
  39. $notice->employee_id = $user_id;
  40. $notice->notice_title = $request->notice_title;
  41. $notice->expire_date = $request->expire_date;
  42. $notice->description = $request->description;
  43. $notice->added_by = $user_id;
  44. $notice->status = 1;
  45. $notice->save();
  46. $tags = $request->input('send_to');
  47. foreach($tags as $key => $file) {
  48. $document = new NoticeSend;
  49. $document->notice_id = $notice->id;
  50. $document->sendto_id = $request['send_to'][$key];
  51. $document->save();
  52. }
  53. return redirect('admin/notice_board')->with('msg','Notice Send Successfu.');
  54. }
  55. public function show($id)
  56. {
  57. $user_id = \Auth::user()->id;
  58. $data['title'] = "Notice Details";
  59. $data['notice'] = DB::table('notice_boards')
  60. ->join('users', 'notice_boards.employee_id', '=', 'users.id')
  61. ->select('notice_boards.*', 'users.name')
  62. ->where('notice_boards.id',$id)->first();
  63. return view('admin.notice_board/details',$data);
  64. }
  65. public function myNotice(){
  66. $user_id = \Auth::user()->id;
  67. $data['title'] = "My add Notice";
  68. $data['notices'] = NoticeBoard::where('employee_id',$user_id)->orderBy('id','DESC')->get();
  69. return view('admin.notice_board/my_notice',$data);
  70. }
  71. public function edit($id)
  72. {
  73. $user_id = \Auth::user()->id;
  74. $data['title'] = "Notice Edit";
  75. $data['employee'] = User::where('employee_id','!=', "")->orWhere('utype',1)->orderBy('id','DESC')->get();
  76. $data['sendto'] = NoticeSend::where('notice_id',$id)->pluck('sendto_id')->toArray();
  77. $data['notice'] = NoticeBoard::find($id);
  78. return view('admin.notice_board/edit',$data);
  79. }
  80. public function update(Request $request, $id)
  81. {
  82. //
  83. }
  84. public function destroy($id)
  85. {
  86. NoticeBoard::whereId($id)->delete();
  87. NoticeSend::where('notice_id',$id)->delete();
  88. return redirect('admin/notice_board/my_notice')->with('msg','Successfully Deleted!');
  89. }
  90. }