NotificationController.php 940 B

12345678910111213141516171819202122232425262728293031323334353637
  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. $notifications = Auth::user()->notifications()->get();
  25. foreach($notifications as $notification){
  26. $notification->markAsRead();
  27. }
  28. return redirect()->back();
  29. }
  30. }