/app/Laravel/Listeners/ReadSelfNotification.php

https://bitbucket.org/cityserv/techreportph · PHP · 38 lines · 22 code · 4 blank · 12 comment · 3 complexity · eb9b67f85a25a67fd04a22638534c7ac MD5 · raw file

  1. <?php
  2. namespace App\Laravel\Listeners;
  3. use Illuminate\Notifications\Events\NotificationSent;
  4. use Illuminate\Queue\InteractsWithQueue;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. class ReadSelfNotification implements ShouldQueue
  7. {
  8. /**
  9. * Create the event listener.
  10. *
  11. * @return void
  12. */
  13. public function __construct()
  14. {
  15. //
  16. }
  17. /**
  18. * Handle the event.
  19. *
  20. * @param NotificationSent $event
  21. * @return void
  22. */
  23. public function handle(NotificationSent $event)
  24. {
  25. $user = $event->notifiable;
  26. if($event->channel == "database") {
  27. foreach ($user->unreadNotifications as $key => $notification) {
  28. if(strpos($notification->type, "App\Laravel\Notifications\Self") !== FALSE) {
  29. $notification->markAsRead();
  30. }
  31. }
  32. }
  33. }
  34. }