render('company/index.html.twig', [ 'companies' => $companyRepository->findAll(), ]); } #[Route('/new', name: 'app_company_new', methods: ['GET', 'POST'])] public function new(Request $request, EntityManagerInterface $entityManager): Response { $company = new Company(); $form = $this->createForm(CompanyType::class, $company); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->persist($company); $entityManager->flush(); return $this->redirectToRoute('app_company_index', [], Response::HTTP_SEE_OTHER); } return $this->render('company/new.html.twig', [ 'company' => $company, 'form' => $form, ]); } #[Route('/{id}', name: 'app_company_show', methods: ['GET'])] public function show(Company $company): Response { return $this->render('company/show.html.twig', [ 'company' => $company, ]); } #[Route('/{id}/edit', name: 'app_company_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Company $company, EntityManagerInterface $entityManager): Response { $form = $this->createForm(CompanyType::class, $company); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->flush(); return $this->redirectToRoute('app_company_index', [], Response::HTTP_SEE_OTHER); } return $this->render('company/edit.html.twig', [ 'company' => $company, 'form' => $form, ]); } #[Route('/{id}', name: 'app_company_delete', methods: ['POST'])] public function delete(Request $request, Company $company, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$company->getId(), $request->getPayload()->getString('_token'))) { $entityManager->remove($company); $entityManager->flush(); } return $this->redirectToRoute('app_company_index', [], Response::HTTP_SEE_OTHER); } }