Dev0ps
1 year ago

How to fetch all unread notification in one query

Posted 1 year ago by Dev0ps

my codes look

 $PostNotifications = PostNotification::whereUserId($user_id)->whereSeen(0)->orderBy('id','desc')->get();
            $FeedbackNotifications = FeedbackNotification::whereUserId($user_id)->whereSeen(0)->orderBy('id','desc')->get();
            $ArticleNotifications = BlogNotification::whereUserId($user_id)->whereSeen(0)->orderBy('id','desc')->get();
            $Notification = Notification::whereUserId($user_id)->whereSeen(0)->orderBy('id','desc')->get();

            $notifications = $PostNotifications->merge($FeedbackNotifications);
        $notifications = $notifications->merge($ArticleNotifications);
        $notifications = $notifications->merge($Notification);
      return  $notifications = $notifications->sortByDesc('created_at');
        $NotificationCounter = collect($notifications)->count('user_id');

is there any way to achieve the same result in a convenient way.

Please sign in or create an account to participate in this conversation.