notifs as $notif) { $entityId = $this->getReference($notif['entityRef'])->getId(); echo 'Adding notification for ' . $notif['entityClass'] . '(entity id:' . $entityId . ")\n"; $newNotif = (new Notification()) ->setMessage($notif['message']) ->setSender($this->getReference($notif['sender'])) ->setRelatedEntityClass($notif['entityClass']) ->setRelatedEntityId($entityId) ->setDate(new DateTimeImmutable('now')) ->setRead([]); foreach ($notif['addressees'] as $addressee) { $newNotif->addAddressee($this->getReference($addressee)); } $manager->persist($newNotif); $manager->flush(); } } }