PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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