select([ 'user_notifications.*', 'notifications.title', 'notifications.message', 'notifications.priority', 'notifications.scheduled_at', 'notifications.expires_at', 'notifications.target_group', ]) ->join('notifications', 'notifications.id', '=', 'user_notifications.notification_id') ->where('user_notifications.user_id', $userId); if (isset($filters['read'])) { $read = filter_var($filters['read'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if ($read !== null) { $query->where('user_notifications.is_read', $read ? 1 : 0); } } $paginator = $query ->orderBy('notifications.' . $sortBy, $sortDir) ->paginate($perPage, ['*'], 'page', $page); return [ 'notifications' => $paginator, 'pagination' => $this->paginationPayload($paginator), ]; } private function paginationPayload(LengthAwarePaginator $paginator): array { return [ 'current_page' => $paginator->currentPage(), 'per_page' => $paginator->perPage(), 'total' => $paginator->total(), 'total_pages' => $paginator->lastPage(), ]; } }