render('skill/index.html.twig', [ 'skills' => $skillRepository->findAll(), ]); } #[Route('/new', name: 'app_skill_new', methods: ['GET', 'POST'])] #[IsGranted('ROLE_ADMIN')] public function new(Request $request, EntityManagerInterface $entityManager): Response { $skill = new Skill(); $form = $this->createForm(SkillType::class, $skill); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->persist($skill); $entityManager->flush(); return $this->redirectToRoute('app_skill_index', [], Response::HTTP_SEE_OTHER); } return $this->render('skill/new.html.twig', [ 'skill' => $skill, 'form' => $form, ]); } #[Route('/{id}', name: 'app_skill_show', methods: ['GET'])] public function show(Skill $skill): Response { return $this->render('skill/show.html.twig', [ 'skill' => $skill, ]); } #[Route('/{id}/edit', name: 'app_skill_edit', methods: ['GET', 'POST'])] #[IsGranted('ROLE_ADMIN')] public function edit(Request $request, Skill $skill, EntityManagerInterface $entityManager): Response { $form = $this->createForm(SkillType::class, $skill); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->flush(); return $this->redirectToRoute('app_skill_index', [], Response::HTTP_SEE_OTHER); } return $this->render('skill/edit.html.twig', [ 'skill' => $skill, 'form' => $form, ]); } #[Route('/{id}', name: 'app_skill_delete', methods: ['POST'])] #[IsGranted('ROLE_ADMIN')] public function delete(Request $request, Skill $skill, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$skill->getId(), $request->getPayload()->getString('_token'))) { $entityManager->remove($skill); $entityManager->flush(); } return $this->redirectToRoute('app_skill_index', [], Response::HTTP_SEE_OTHER); } }