src/Notification/NotificationRepository.php
public function findByUser(User $user, $limit = null, $offset = 0)
    {
        $primaries = Notification::select(
            app('flarum.db')->raw('MAX(id) AS id'),
            app('flarum.db')->raw('SUM(read_at IS NULL) AS unread_count')
        )
            ->where('user_id', $user->id)
            ->whereIn('type', $user->getAlertableNotificationTypes())
            ->where('is_deleted', false)
            ->whereSubjectVisibleTo($user)
            ->groupBy('type', 'subject_id')
            ->orderByRaw('MAX(created_at) DESC')
            ->skip($offset)
            ->take($limit);

        return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count'))
            ->mergeBindings($primaries->getQuery())
            ->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id'))
            ->latest()
            ->get();
    }
public function findByUser(User $user, $limit = null, $offset = 0)
    {
        $primaries = Notification::select(
            app('flarum.db')->raw('MAX(id) AS id'),
            app('flarum.db')->raw('SUM(read_at IS NULL) AS unread_count')
        )
            ->where('user_id', $user->id)
            ->whereIn('type', $user->getAlertableNotificationTypes())
            ->where('is_deleted', false)
            ->whereSubjectVisibleTo($user)
            ->groupBy('type', 'subject_id')
            ->orderByRaw('MAX(created_at) DESC')
            ->skip($offset)
            ->take($limit);

        return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count'))
            ->mergeBindings($primaries->getQuery())
            ->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id'))
            ->latest()
            ->get();
    }
public function findByUser ( User $ user , $ limit = null , $ offset = 0 ) { $ primaries = Notification :: select ( app ( 'flarum.db' ) -> raw ( 'MAX(id) AS id' ) , app ( 'flarum.db' ) -> raw ( 'SUM(read_at IS NULL) AS unread_count' ) ) -> where ( 'user_id' , $ user -> id ) -> whereIn ( 'type' , $ user -> getAlertableNotificationTypes ( ) ) -> where ( 'is_deleted' , false ) -> whereSubjectVisibleTo ( $ user ) -> groupBy ( 'type' , 'subject_id' ) -> orderByRaw ( 'MAX(created_at) DESC' ) -> skip ( $ offset ) -> take ( $ limit ) ; return Notification :: select ( 'notifications.*' , app ( 'flarum.db' ) -> raw ( 'p.unread_count' ) ) -> mergeBindings ( $ primaries -> getQuery ( ) ) -> join ( app ( 'flarum.db' ) -> raw ( '(' . $ primaries -> toSql ( ) . ') p' ) , 'notifications.id' , '=' , app ( 'flarum.db' ) -> raw ( 'p.id' ) ) -> latest ( ) -> get ( ) ; }
Find a user's notifications.

@param User $user
@param int|null $limit
@param int $offset
@return \Illuminate\Database\Eloquent\Collection
Find a user s notifications .