where('user_id', $userId) ->where('created_at', '>=', $since) ->orderByDesc('created_at') ->orderByDesc('id') ->get() ->map(fn (NotificationModel $model): NotificationSummary => new NotificationSummary( $model->id, $model->type, $model->params, $model->created_at->setTimezone((string) config('app.business_timezone'))->format('Y-m-d H:i'), $model->seen_at !== null, )) ->values() ->all(); } public function unseenCount(int $userId, DateTimeImmutable $since): int { return NotificationModel::query() ->where('user_id', $userId) ->where('created_at', '>=', $since) ->whereNull('seen_at') ->count(); } }