entityManager->getRepository(Article::class)->findAll(); foreach ($articles as $article) { $slug = $this->slugger->slug($article->getTitle())->lower(); $existingSlug = $slug; // Vérification des conflits $count = 1; while ($this->entityManager->getRepository(Article::class)->findOneBy(['slug' => $existingSlug])) { $existingSlug = $slug . '-' . $count; $count++; } $article->setSlug($existingSlug); $this->entityManager->persist($article); } $this->entityManager->flush(); } }