NotificationController.php 951 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\Auth;
  4. class NotificationController extends Controller
  5. {
  6. /** Display a listing of the resource. */
  7. public function index()
  8. {
  9. $notifications = Auth::user()->notifications()->paginate();
  10. return view('notifications.index')->with([
  11. 'notifications' => $notifications,
  12. ]);
  13. }
  14. /** Display the specified resource. */
  15. public function show(string $id)
  16. {
  17. $notification = Auth::user()->notifications()->findOrFail($id);
  18. $notification->markAsRead();
  19. return view('notifications.show')->with([
  20. 'notification' => $notification,
  21. ]);
  22. }
  23. public function readAll()
  24. {
  25. $notifications = Auth::user()->notifications()->get();
  26. foreach ($notifications as $notification) {
  27. $notification->markAsRead();
  28. }
  29. return redirect()->back();
  30. }
  31. }