NotificationController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Http\Controllers\Application;
  3. use Auth;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. class NotificationController extends Controller
  7. {
  8. public function __construct()
  9. {
  10. $this->middleware('admin');
  11. }
  12. /**
  13. * Display a listing of the resource.
  14. *
  15. * @return \Illuminate\Http\Response
  16. */
  17. public function index()
  18. {
  19. $user = Auth::guard('admin')->user();
  20. return view('application.notifications.notifications');
  21. }
  22. public function partial()
  23. {
  24. $user = Auth::guard('admin')->user();
  25. $notifications = $user->notifications()->paginate(30);
  26. return view('application.notifications.notification_partial',compact('notifications'));
  27. }
  28. public function markAsRead(Request $request)
  29. {
  30. $user = Auth::user();
  31. $notification = $user->unreadNotifications()->where('id',$request->id)->first();
  32. if ($notification){
  33. $notification->markAsRead();
  34. }
  35. echo 'success';
  36. }
  37. public function markAllAsRead()
  38. {
  39. $user = Auth::user();
  40. $notifications = $user->unreadNotifications()->get();
  41. foreach ($notifications as $key => $notification) {
  42. $notification->markAsRead();
  43. }
  44. return redirect()->back();
  45. }
  46. }