public function markAsRead($notifications = null)
    {
        // If we don't pass notifications, mark all as read for the current logged in user
        $user = Craft::$app->getUser();
        if ($user && is_null($notifications)) {
            $notifications = NotificationsRecord::find()->where(['notifiable' => $user->getId()])->all();
        }

        // Make sure we have a collection to loop over
        $notifications = collect($notifications);

        $notificationIds = $notifications->map(function ($notification) {
            return is_object($notification) ? $notification->id : $notification;
        });

        // Update the read notifications
        if (! is_null($notificationIds)) {
            $now = DateTimeHelper::currentUTCDateTime()->format('Y-m-d H:i:s');
            NotificationsRecord::updateAll(['read_at' => $now], ['id' => $notificationIds]);
        }
    }
public function markAsRead($notifications = null)
    {
        // If we don't pass notifications, mark all as read for the current logged in user
        $user = Craft::$app->getUser();
        if ($user && is_null($notifications)) {
            $notifications = NotificationsRecord::find()->where(['notifiable' => $user->getId()])->all();
        }

        // Make sure we have a collection to loop over
        $notifications = collect($notifications);

        $notificationIds = $notifications->map(function ($notification) {
            return is_object($notification) ? $notification->id : $notification;
        });

        // Update the read notifications
        if (! is_null($notificationIds)) {
            $now = DateTimeHelper::currentUTCDateTime()->format('Y-m-d H:i:s');
            NotificationsRecord::updateAll(['read_at' => $now], ['id' => $notificationIds]);
        }
    }
public function markAsRead ( $ notifications = null ) { // If we don't pass notifications, mark all as read for the current logged in user $ user = Craft :: $ app -> getUser ( ) ; if ( $ user && is_null ( $ notifications ) ) { $ notifications = NotificationsRecord :: find ( ) -> where ( [ 'notifiable' => $ user -> getId ( ) ] ) -> all ( ) ; } // Make sure we have a collection to loop over $ notifications = collect ( $ notifications ) ; $ notificationIds = $ notifications -> map ( function ( $ notification ) { return is_object ( $ notification ) ? $ notification -> id : $ notification ; } ) ; // Update the read notifications if ( ! is_null ( $ notificationIds ) ) { $ now = DateTimeHelper :: currentUTCDateTime ( ) -> format ( 'Y-m-d H:i:s' ) ; NotificationsRecord :: updateAll ( [ 'read_at' => $ now ] , [ 'id' => $ notificationIds ] ) ; } }
Mark a notification as read

@param $notifications
Mark a notification as read