Hi I'm having troubles getting a list of all "blog tag" entities in the index function of my controller.
I tried using normalizer groups but somehow I still get a circular reference error. I expect my controller to output a list of blog tags, by id and name.
This is my controller:
#[Route('/', name: 'api_blogtag_index', methods: ['GET'])]
#[IsGranted('IS_AUTHENTICATED')]
public function index(BlogtagRepository $blogtagRepository): Response
{
return $this->json([
'tags' => $blogtagRepository->findAll(),
Response::HTTP_OK, [], [
AbstractNormalizer::GROUPS => ['show_blogtag']
]
]);
}
And this is the blog tag entity class:
#[ORM\Entity(repositoryClass: BlogtagRepository::class)]
class Blogtag
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['show_blogtag'])]
private ?int $id = null;
#[ORM\Column(length: 255, unique: true)]
#[Groups(['show_blogtag'])]
private ?string $name = null;
#[ORM\ManyToMany(targetEntity: Blog::class, inversedBy: 'blogtags')]
private Collection $blogs;