firstOrCreate( ['dedupe_key' => $notification->dedupeKey], [ 'user_id' => $notification->userId, 'type' => $notification->type, 'params' => $notification->params, 'created_at' => $notification->createdAt, ], ); return $model->wasRecentlyCreated; } public function markSeen(int $userId, DateTimeImmutable $at): void { NotificationModel::query() ->where('user_id', $userId) ->whereNull('seen_at') ->update(['seen_at' => $at]); } public function deleteOlderThan(DateTimeImmutable $moment): void { NotificationModel::query()->where('created_at', '<', $moment)->delete(); } }