# fluent-community/trunk/app/Http/Controllers/NotificationsController.php

FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS &amp; Online Courses, version trunk. 109 lines.

- Page: https://pluginprobe.com/plugins/fluent-community/trunk/code/app/Http/Controllers/NotificationsController.php
- Raw: https://pluginprobe.com/plugins/fluent-community/trunk/raw/app/Http/Controllers/NotificationsController.php
- Modified: 2026-09-14T14:31:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-community/trunk/code/app/Http/Controllers/NotificationsController.php#L10-L20`.

```php
<?php

namespace FluentCommunity\App\Http\Controllers;

use FluentCommunity\App\Http\Controllers\Controller;
use FluentCommunity\App\Models\Feed;
use FluentCommunity\App\Models\Notification;
use FluentCommunity\App\Models\NotificationSubscriber;
use FluentCommunity\App\Services\ProfileHelper;
use FluentCommunity\Framework\Http\Request\Request;

class NotificationsController extends Controller
{
    public function getNotifications(Request $request)
    {
        $user = $this->getUser(true);

        $notifications = Notification::whereHas('subscribers', function ($query) use ($user) {
            return $query->where('user_id', $user->ID);
        })
            ->with([
                'xprofile'   => function ($q) {
                    return $q->select(ProfileHelper::getXProfilePublicFields());
                },
                'subscriber' => function ($q) {
                    return $q->where('user_id', get_current_user_id());
                }
            ])
            ->byStatus($request->get('status'), $user->ID)
            ->byType($request->get('notification_type', 'all'))
            ->orderBy('updated_at', 'DESC')
            ->paginate();

        $data = [
            'notifications' => $notifications,
            'unread_count'  => Notification::byStatus('unread', $user->ID)->count()
        ];
        return apply_filters('fluent_community/notifications_api_response', $data, $request->all());
    }

    public function getUnreadNotifications(Request $request)
    {
        $user = $this->getUser(true);

        $unreadNotifications = Notification::byStatus('unread', $user->ID)
            ->with(['xprofile' => function ($q) {
                return $q->select(ProfileHelper::getXProfilePublicFields());
            }])
            ->orderBy('updated_at', 'DESC')
            ->byType($request->get('notification_type', 'all'))
            ->limit(50)
            ->get();

        $data = [
            'notifications' => $unreadNotifications,
            'unread_count'  => Notification::byStatus('unread', get_current_user_id())->count()
        ];

        return apply_filters('fluent_community/unread_notifications_api_response', $data, $request->all());
    }

    public function markAllRead(Request $request)
    {
        NotificationSubscriber::where('is_read', 0)
            ->where('user_id', get_current_user_id())
            ->update(['is_read' => 1]);

        return [
            'message' => __('All notifications have been marked as read.', 'fluent-community')
        ];
    }

    public function markAsRead(Request $request, $notification_id)
    {
        $notification = Notification::findOrFail($notification_id);

        NotificationSubscriber::whereHas('notification', function ($query) use ($notification) {
            $query->where('id', $notification->id);
            if ($notification->feed_id) {
                $query->orWhere('feed_id', $notification->feed_id);
            }
        })
            ->where('user_id', get_current_user_id())
            ->update(['is_read' => 1]);

        return [
            'unread_count' => Notification::byStatus('unread', get_current_user_id())->count()
        ];
    }

    public function markAsReadByFeedId(Request $request, $feedId)
    {
        $feed = Feed::withoutGlobalScopes()->findOrFail($feedId);

        NotificationSubscriber::whereHas('notification', function ($query) use ($feed) {
            return $query->where('feed_id', $feed->id);
        })
            ->where('user_id', get_current_user_id())
            ->update(['is_read' => 1]);

        $userModel = $this->getUser();

        return [
            'unread_notification_count' => $userModel->getUnreadNotificationCount(),
            'unread_feed_ids'           => $userModel->getUnreadNotificationFeedIds(),
        ];
    }
}

```
